1、 一维抛物线偏微分方程数值解法(4)上一篇参看 一维抛物线偏微分方程数值解法(3) (附图及matlab程序)解一维抛物线型方程(理论书籍可以参看孙志忠:偏微分方程数值解法)Ut-Uxx=0, 00) U(x,0)=ex, 0 title(误差); 运行约43秒;u p e x t=JCHGS(0.1,0.01,10,100);surf(x,t,e) 20多秒;u p e x t=JCHGS(0.2,0.04,5,25);surf(x,t,e) 3秒;此方法精度很高;二:g-s 迭代法求解线性方程组Matlab 程序function u e p x t k=JCFGS1(h1,h2,m,n,k
2、max,ep)% 解抛物线型一 维方程 格式 (Ut-aUxx=f(x,t),a0)%用g-s(高斯-赛德尔)迭代法解%kmax为 最大迭代次数%m,n为 x,t方向的网格数,例如(2-0)/0.01=200;%e为误差,p为精确解syms temp;u=zeros(n+1,m+1);x=0+(0:m)*h1;t=0+(0:n)*h2;for(i=1:n+1)u(i,1)=exp(t(i);u(i,m+1)=exp(1+t(i);end for(i=1:m+1)u(1,i)=exp(x(i);endfor(i=1:n+1)for(j=1:m+1)f(i,j)=0;endenda=zeros(n
3、,m-1);r=h2/(h1*h1); %此处r=a*h2/(h1*h1) ;a=1for(k=1:kmax)for(i=1:n)for(j=2:m)temp=(1/12+r/2)*(u(i,j-1)+u(i,j+1)+(5/6-r)*u(i,j)+.h2/12*(f(i,j-1)+10*f(i,j)+f(i,j+1)+(r/2-1/12)*(u(i+1,.j-1)+u(i+1,j+1)/(5/6+r);a(i+1,j)=(temp-u(i+1,j)*(temp-u(i+1,j);u(i+1,j)=temp;%此处注意是u(i+1,j),而不是u(i+1,j+1)%endenda(i+1,j)=sqrt(a(i+1,j);if(kkmax)break;endif(max(max(a)ep)break; endendfor(i=1:n+1)for(j=1:m+1)p(i,j)=exp(x(j)+t(i);e(i,j)=abs(u(i,j)-p(i,j);endendu e p x t k=JCFGS1(0.1,0.005,10,200,100000,1e-12);k=67;运行速度 1 秒左右;surf(x,t,e)u e p x t k=JCFGS1(0.01,0.001,100,1000,1000000,1e-12);k=5780;surf(x,t,e)