首页 > 解决方案 > 使用 ggplot 对 pde 有限差分法进行动画处理

问题描述

我有一个功能:



NLUpwindBurgers = function(Nx,Nt,t_end){
  Nx = Nx+1
  xmax = 1
  xmin = 0
  h = (xmax-xmin)/(Nx-1)
  x = seq(xmin,xmax,by = h)
  U = exp(-10*(4*x-1)^2)
  dt = 1/Nt
  t = 0

  while (t <= t_end){ 
    v = dt/h
    t = t+dt
    Un = U
    Um = shift(Un,1)
    Up = shift(Un,-1)
    F_plus = 1/2 * (Up + Un)
    F_minus = 1/2 * (Un + Um)
    U= Un-1/2*v*(F_minus+F_minus)*(Un-Um)- 1/2 * v * (F_plus  - F_plus)  * (Up-Un)}
    plot(x,U,type = "l")}

NLUpwindBurgers(100,100,0.0)
NLUpwindBurgers(100,100,0.1)

我想为时间演化的函数设置动画,比如从 t0 =0 到 t_{n}=1。但是阅读 gganimate 我无法弄清楚我该怎么做?有什么帮助吗?

标签: rfunctionggplot2pdegganimate

解决方案


推荐阅读