为什么我的matlab图没有使用有限差分法进化?

时间:2016-04-07 02:20:37

标签: matlab plot pde

我正在尝试使用有限差分方法来求解给定函数u0的热方程。我希望使用图表来及时发展它以查看每个帧的变化,但是当我运行它时,我看到的是一遍又一遍的相同帧。由于我没有给出“u”第一个或最后一个索引会导致解决方案中出现更多的整体错误,因此我知道最终的错误。我不是很擅长matlab所以我不确定我是否正确地编写了我的嵌套片段。

% set up domain in time and space 
 t_step = .1;
 tspan = [0 :t_step:1000];
 L = 10; %length of domain
 n = 64; 
 dx = 2*pi/(n-1); %spacing
 x = 0:dx:2*pi; 
 x = x'; %make x vertical vector


% initial conditions for the function
u0 = sin(2*pi*x/L)+0*cos(3*2*pi*x/L) + 0.2*(cos(5*2*pi*x/L))+0*randn(size(x));

plot(x,u0);title('initial condition');pause;

t = 0;

for m = 1:tspan(end)
     u = u0;
     t = t + t_step;

         for j= 2:n-1
               u(j,m) = u0(j-1) - 2*u0(j) + u0(j+1)/dx^2; %u(1) and n left out

          end

     plot(x,u(:,m))
     pause(0.01);

end 

0 个答案:

没有答案
相关问题