您好,欢迎访问三七文档
当前位置:首页 > 办公文档 > 会议纪要 > 偏微分方程数值解法题解
偏微分方程数值解法(带程序)例1求解初边值问题22,(0,1),012,(0,]2(,0)12(1),[,1)2(0,)(1,)0,0uuxttxxxuxxxututt要求采用树脂格式111(2)nnnnnjjjjjuuuuu,2()tx,完成下列计算:(1)取0.1,0.1,x分别计算0.01,0.02,0.1,t时刻的数值解。(2)取0.1,0.5,x分别计算0.01,0.02,0.1,t时刻的数值解。(3)取0.1,1.0,x分别计算0.01,0.02,0.1,t时刻的数值解。并与解析解22()22181(,)sin()sin()2ntnunxtnxen进行比较。解:程序functionA=zhongxinchafen(x,y,la)U=zeros(length(x),length(y));fori=1:size(x,2)ifx(i)0&x(i)=0.5U(i,1)=2*x(i);elseifx(i)0.5&x(i)1U(i,1)=2*(1-x(i));endendforj=1:length(y)-1fori=1:length(x)-2U(i+1,j+1)=U(i+1,j)+la*(U(i+2,j)-2*U(i+1,j)+U(i,j));endendA=U(:,size(U,2))functionu=jiexijie1(x,t)fori=1:size(x,2)k=3;-1-a1=(1/(1^2)*sin(1*pi/2)*sin(1*pi*x(i))*exp(-1^2*pi^2*t));a2=a1+(1/(2^2)*sin(2*pi/2)*sin(2*pi*x(i))*exp(-2^2*pi^2*t));whileabs(a2-a1)0.00001a1=a2;a2=a1+(1/(k^2)*sin(k*pi/2)*sin(k*pi*x(i))*exp(-k^2*pi^2*t));k=k+1;endu(i)=8/(pi^2)*a2;endclc;%第1题第1问clear;t1=0.01;t2=0.02;t3=0.1;x=[0:0.1:1];y1=[0:0.001:t1];y2=[0:0.001:t2];y3=[0:0.001:t3];la=0.1;subplot(131)A1=zhongxinchafen(x,y1,la);u1=jiexijie1(x,t1)line(x,A1,'color','r','linestyle',':','linewidth',1.5);holdonline(x,u1,'color','b','linewidth',1);A2=zhongxinchafen(x,y2,la);u2=jiexijie1(x,t2)line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,u2,'color','b','linewidth',1);A3=zhongxinchafen(x,y3,la);u3=jiexijie1(x,t3)line(x,A3,'color','r','linestyle',':','linewidth',1.5);line(x,u3,'color','b','linewidth',1);title('例1(1)');subplot(132);line(x,u1,'color','b','linewidth',1);line(x,u2,'color','b','linewidth',1);line(x,u3,'color','b','linewidth',1);title('解析解');subplot(133);line(x,A1,'color','r','linestyle',':','linewidth',1.5);line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,A3,'color','r','linestyle',':','linewidth',1.5);title('数值解');clc;%第1题第2问clear;t1=0.01;t2=0.02;t3=0.1;x=[0:0.1:1];y1=[0:0.005:t1];y2=[0:0.005:t2];y3=[0:0.005:t3];la=0.5;subplot(131);A1=zhongxinchafen(x,y1,la);u1=jiexijie1(x,t1)line(x,A1,'color','r','linestyle',':','linewidth',1.5);holdonline(x,u1,'color','b','linewidth',1);A2=zhongxinchafen(x,y2,la);u2=jiexijie1(x,t2)line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,u2,'color','b','linewidth',1);A3=zhongxinchafen(x,y3,la);u3=jiexijie1(x,t3)-2-line(x,A3,'color','r','linestyle',':','linewidth',1.5);line(x,u3,'color','b','linewidth',1);title('例1(2)');subplot(132);line(x,u1,'color','b','linewidth',1);line(x,u2,'color','b','linewidth',1);line(x,u3,'color','b','linewidth',1);title('解析解');subplot(133);line(x,A1,'color','r','linestyle',':','linewidth',1.5);line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,A3,'color','r','linestyle',':','linewidth',1.5);title('数值解');clc;%第1题第3问clear;t1=0.01;t2=0.02;t3=0.1;x=[0:0.1:1];y1=[0:0.01:t1];y2=[0:0.01:t2];y3=[0:0.01:t3];la=1.0;subplot(131);A1=zhongxinchafen(x,y1,la);u1=jiexijie1(x,t1)line(x,A1,'color','r','linestyle',':','linewidth',1.5);holdonline(x,u1,'color','b','linewidth',1);A2=zhongxinchafen(x,y2,la);u2=jiexijie1(x,t2)line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,u2,'color','b','linewidth',1);A3=zhongxinchafen(x,y3,la);u3=jiexijie1(x,t3)line(x,A3,'color','r','linestyle',':','linewidth',1.5);line(x,u3,'color','b','linewidth',1);title('例1(3)');subplot(132);line(x,u1,'color','b','linewidth',1);line(x,u2,'color','b','linewidth',1);line(x,u3,'color','b','linewidth',1);title('解析解');subplot(133);line(x,A1,'color','r','linestyle',':','linewidth',1.5);line(x,A2,'color','r','linestyle',':','linewidth',1.5);line(x,A3,'color','r','linestyle',':','linewidth',1.5);title('数值解');运行结果:表1:取0.1,0.1,x0.01,0.02,0.1,t时刻的解析解与数值解时间(t)解析解数值解时间(t)解析解数值解时间(t)解析解数值解0.01t000.02t000.1t000.22690.19960.20560.19390.09340.09440.43170.39680.39110.37810.17760.17960.59410.58220.53830.53730.24440.24720.69840.72810.63280.64870.28730.29070.73440.78670.66540.68910.30210.30560.69840.72810.63280.64870.28730.2907-3-0.59410.58220.53830.53730.24440.24720.43170.39680.39110.37810.17760.17960.22690.19960.20560.19390.09340.09440.000000.000000.00000表2:取0.1,0.5,x0.01,0.02,0.1,t时刻的解析解与数值解时间(t)解析解数值解时间(t)解析解数值解时间(t)解析解数值解0.01t000.02t000.1t000.22690.20000.20560.20000.09340.09490.43170.40000.39110.37500.17760.17170.59410.60000.53830.55000.24440.24840.69840.70000.63280.62500.28730.27780.73440.80000.66540.70000.30210.30710.69840.70000.63280.62500.28730.27780.59410.60000.53830.55000.24440.24840.43170.40000.39110.37500.17760.17170.22690.20000.20560.20000.09340.09490.000000.000000.00000表3:取0.1,1.0,x0.01,0.02,0.1,t时刻的解析解与数值解时间(t)解析解数值解时间(t)解析解数值解时间(t)解析解数值解0.01t000.02t000.1t000.22690.20000.20560.20000.0934220.2000.43170.40000.39110.40000.1776-453.6000.59410.60000.53830.60000.2444684.6000.69840.80000.63280.40000.2873-861.2000.73440.60000.66541.00000.3021929.0000.69840.80000.63280.40000.2873-861.2000.59410.60000.53830.60000.2444684.6000.43170.40000.39110.40000.1776-453.6000.22690.20000.20560.20000.0934220.2000.000000.000000.00000-4-图1:取0.1,0.1,x0.01,0.02,0.1,t时刻的解析解与数值解图2:取0.1,0.5,x0.01,0.02,0.1,t时刻的解析解与数值解-5-图3:取0.1,1.0,
本文标题:偏微分方程数值解法题解
链接地址:https://www.777doc.com/doc-2694362 .html