预览加载中,请您耐心等待几秒...
1/9
2/9
3/9
4/9
5/9
6/9
7/9
8/9
9/9

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

偏微分方程数值解上机实验报告(一)实验一上机题目:用线性元求解下列边值问题的数值解:-y''+π24y=π22sinπ2x,0<x<1y(0)=0,y'1=0实验程序:functionS=bzx=fzero(@zfun,1);[ty]=ode45(@odefun,[01],[0x]);S.t=t;S.y=y;plot(t,y)xlabel('x:´从0一直到1')ylabel('y')title('线性元求解边值问题的数值解')functiondy=odefun(x,y)dy=[00]';dy(1)=y(2);dy(2)=(pi^2)/4*y(1)-((pi^2)/2)*sin(x*pi/2);functionz=zfun(x);[ty]=ode45(@odefun,[01],[0x]);z=y(end)-0;实验结果:1.以步长h=0.05进行逐步运算,运行上面matlab程序结果如下:2.在0<x<1区间上,随着x的不断变化,x,y之间关系如下图所示:(二)实验二上机题目:求解Helmholtz方程的边值问题:,于,于其中k=1,5,10,15,20实验程序:(采用有限元方法,这里对[0,1]*[0,1]采用n*n的划分,n为偶数)n=10;a=zeros(n);f=zeros(n);b=zeros(1,n);U=zeros(n,1);u=zeros(n,1);fori=2:na(i-1,i-1)=pi^2/(12*n)+n;a(i-1,i)=pi^2/(24*n)-n;a(i,i-1)=pi^2/(24*n)-n;forj=1:nifj==i-1a(i,j)=a(i,i-1);elseifj==ia(i-1,j-1)=2*a(i-1,i-1);elseifj==i+1a(i,j)=a(i,i+1);elsea(i,j)=0;endendendendenda(n,n)=pi^2/(12*n)+n;fori=2:nf(i-1,i)=4/pi*cos((i-1)*pi/2/n)-8*n/(pi^2)*sin(i*pi/2/n)+8*n/(pi^2)*sin((i-1)*pi/2/n);endfori=1:nf(i,i)=-4/pi*cos(i*pi/2/n)+8*n/(pi^2)*sin(i*pi/2/n)-8*n/(pi^2)*sin((i-1)*pi/2/n);end%b(j)=f(i-1,j)+f(i,j)fori=1:(n-1)b(i)=f(i,i)+f(i,i+1);endb(n)=f(n,n);tic;n=20;can=20;s=zeros(n^2,10);h=1/n;st=1/(2*n^2);A=zeros((n+1)^2,(n+1)^2);symsxy;fork=1:1:2*n^2s(k,1)=k;q=fix(k/(2*n));r=mod(k,(2*n));if(r~=0)r=r;elser=2*n;q=q-1;endif(r<=n)s(k,2)=q*(n+1)+r;s(k,3)=q*(n+1)+r+1;s(k,4)=(q+1)*(n+1)+r+1;s(k,5)=(r-1)*h;s(k,6)=q*h;s(k,7)=r*h;s(k,8)=q*h;s(k,9)=r*h;s(k,10)=(q+1)*h;elses(k,2)=q*(n+1)+r-n;s(k,3)=(q+1)*(n+1)+r-n+1;s(k,4)=(q+1)*(n+1)+r-n;s(k,5)=(r-n-1)*h;s(k,6)=q*h;s(k,7)=(r-n)*h;s(k,8)=(q+1)*h;s(k,9)=(r-n-1)*h;s(k,10)=(q+1)*h;endendd=zeros(3,3);B=zeros((n+1)^2,1);b=zeros(3,1);fork=1:1:2*n^2L(1)=(1/(2*st))*((s(k,7)*s(k,10)-s(k,9)*s(k,8))+(s(k,8)-s(k,10))*x+(s(k,9)-s(k,7))*y);L(2)=(1/(2*st))*((s(k,9)*s(k,6)-s(k,5)*s(k,10))+(s(k,10)-s(k,6))*x+(s(k,5)-s(k,9))*y);L(3)=(1/(2*st))*((s(k,5)*s(k,8)-s(k,7)*s(k,6))+(s(k,6)-s(k,8))*x+(s(k,7)-s(k,5))*y);fori=1:1:3forj=i:3d(i,j)=int(int(((((diff(L(i),x))*(diff(L(j),x)))+((diff(L(i),y))*(diff(L(j),y))))-((can^2)*L(i)*L(j))),x,0,1),y,0,1);d