欢迎来到天天文库
浏览记录
ID:45605119
大小:408.95 KB
页数:25页
时间:2019-11-15
《数学专业计算实习作业1》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、用有限差分法求解正方形域上的Poisson方程边值问题d2u*d2udx2dy2丿=/(X,y)=1,02、NN)52n)3、,N)"诂T咖=9或99,则㈡(1)用Jacobi迭代法求解线性方程组Aii=foJacobi迭代法对k=0丄2…Dx(k+i)=(L+〃)r)+b即严)=BjX{k}其小迭代矩阵巧=D^(L+U)=I-D'lA右端向量g=zr%分量形式铲)=(bt-£勺兀『-£知兀『)/~=(®-£知町))/给j=lj=i+lj=程序:%Jacobi迭代法funclion[U,k,er,t]二jacobi(n)%变量说明:%U—-方程组的解%h---步长%A—-迭代矩阵%k一-迭代次数%n-一非边界点数%f一-线性方程组A*U4、=f的右端矩阵f%e—允许误差界%ei——迭代误差%t一-计算时间h=l/(n+l);f(2:n+l,2:n+l)=h"2;%初始化fU=zeros(n+2);%初始化U为n+2阶零矩阵e二0.000000001;%设置谋差界forj=0:n+l%设置矩阵A,L•边界点的值U(l,j+1)二j*h*(l-j*h);U(n+2,j+l)=U(l,j+1);U(j+1,l)=j*h*(l-j*h);U(j+l,n+2)=U(j+l,1);endA二U%迭代求解tic;fork=l:10000er=0;max=0;fori5、二2:n+lforj二2:n+lA(i,j)=(U(i-l,j)+U(i+l,j)+U(i,j+l)+U(i,j-l)+f(i,j))/4;er=abs(A(i,j)-U(i,j));%估计当前误并ifer>maxmax=er;endendendU二A;ifmax6、0.14160.18810.16000.18810.21710.21000.22380.24110.24000.24600.25670.25000.25350.26210.24000.24600.25670.21000.22380.24110.16000.18810.21710.09000.14160.188100.09000.16000.21000.24000.25000.22380.24600.25350.24110.25670.26210.25680.26760.27130.26760.27540.27820.7、27130.27820.28070.26760.27540.27820.25680.26760.27130.24110.25670.26210.22380.24600.25350.21000.24000.25000.24000.21000.16000.24600.22380.18810.25670.24110.21710.26760.25680.24110.27540.26760.25670.27820.27130.26210.27540.26760.25670.26760.25680.24110.25670.2418、10.21710.24600.22380.18810.24000.21000.1600Columns10through110.09000.14160.18810.22380.24600.25350.24600.22380.18810.14160.090000.09000.16000.21000.24000.25000.24000.21000.1
2、NN)52n)3、,N)"诂T咖=9或99,则㈡(1)用Jacobi迭代法求解线性方程组Aii=foJacobi迭代法对k=0丄2…Dx(k+i)=(L+〃)r)+b即严)=BjX{k}其小迭代矩阵巧=D^(L+U)=I-D'lA右端向量g=zr%分量形式铲)=(bt-£勺兀『-£知兀『)/~=(®-£知町))/给j=lj=i+lj=程序:%Jacobi迭代法funclion[U,k,er,t]二jacobi(n)%变量说明:%U—-方程组的解%h---步长%A—-迭代矩阵%k一-迭代次数%n-一非边界点数%f一-线性方程组A*U4、=f的右端矩阵f%e—允许误差界%ei——迭代误差%t一-计算时间h=l/(n+l);f(2:n+l,2:n+l)=h"2;%初始化fU=zeros(n+2);%初始化U为n+2阶零矩阵e二0.000000001;%设置谋差界forj=0:n+l%设置矩阵A,L•边界点的值U(l,j+1)二j*h*(l-j*h);U(n+2,j+l)=U(l,j+1);U(j+1,l)=j*h*(l-j*h);U(j+l,n+2)=U(j+l,1);endA二U%迭代求解tic;fork=l:10000er=0;max=0;fori5、二2:n+lforj二2:n+lA(i,j)=(U(i-l,j)+U(i+l,j)+U(i,j+l)+U(i,j-l)+f(i,j))/4;er=abs(A(i,j)-U(i,j));%估计当前误并ifer>maxmax=er;endendendU二A;ifmax6、0.14160.18810.16000.18810.21710.21000.22380.24110.24000.24600.25670.25000.25350.26210.24000.24600.25670.21000.22380.24110.16000.18810.21710.09000.14160.188100.09000.16000.21000.24000.25000.22380.24600.25350.24110.25670.26210.25680.26760.27130.26760.27540.27820.7、27130.27820.28070.26760.27540.27820.25680.26760.27130.24110.25670.26210.22380.24600.25350.21000.24000.25000.24000.21000.16000.24600.22380.18810.25670.24110.21710.26760.25680.24110.27540.26760.25670.27820.27130.26210.27540.26760.25670.26760.25680.24110.25670.2418、10.21710.24600.22380.18810.24000.21000.1600Columns10through110.09000.14160.18810.22380.24600.25350.24600.22380.18810.14160.090000.09000.16000.21000.24000.25000.24000.21000.1
3、,N)"诂T咖=9或99,则㈡(1)用Jacobi迭代法求解线性方程组Aii=foJacobi迭代法对k=0丄2…Dx(k+i)=(L+〃)r)+b即严)=BjX{k}其小迭代矩阵巧=D^(L+U)=I-D'lA右端向量g=zr%分量形式铲)=(bt-£勺兀『-£知兀『)/~=(®-£知町))/给j=lj=i+lj=程序:%Jacobi迭代法funclion[U,k,er,t]二jacobi(n)%变量说明:%U—-方程组的解%h---步长%A—-迭代矩阵%k一-迭代次数%n-一非边界点数%f一-线性方程组A*U
4、=f的右端矩阵f%e—允许误差界%ei——迭代误差%t一-计算时间h=l/(n+l);f(2:n+l,2:n+l)=h"2;%初始化fU=zeros(n+2);%初始化U为n+2阶零矩阵e二0.000000001;%设置谋差界forj=0:n+l%设置矩阵A,L•边界点的值U(l,j+1)二j*h*(l-j*h);U(n+2,j+l)=U(l,j+1);U(j+1,l)=j*h*(l-j*h);U(j+l,n+2)=U(j+l,1);endA二U%迭代求解tic;fork=l:10000er=0;max=0;fori
5、二2:n+lforj二2:n+lA(i,j)=(U(i-l,j)+U(i+l,j)+U(i,j+l)+U(i,j-l)+f(i,j))/4;er=abs(A(i,j)-U(i,j));%估计当前误并ifer>maxmax=er;endendendU二A;ifmax6、0.14160.18810.16000.18810.21710.21000.22380.24110.24000.24600.25670.25000.25350.26210.24000.24600.25670.21000.22380.24110.16000.18810.21710.09000.14160.188100.09000.16000.21000.24000.25000.22380.24600.25350.24110.25670.26210.25680.26760.27130.26760.27540.27820.7、27130.27820.28070.26760.27540.27820.25680.26760.27130.24110.25670.26210.22380.24600.25350.21000.24000.25000.24000.21000.16000.24600.22380.18810.25670.24110.21710.26760.25680.24110.27540.26760.25670.27820.27130.26210.27540.26760.25670.26760.25680.24110.25670.2418、10.21710.24600.22380.18810.24000.21000.1600Columns10through110.09000.14160.18810.22380.24600.25350.24600.22380.18810.14160.090000.09000.16000.21000.24000.25000.24000.21000.1
6、0.14160.18810.16000.18810.21710.21000.22380.24110.24000.24600.25670.25000.25350.26210.24000.24600.25670.21000.22380.24110.16000.18810.21710.09000.14160.188100.09000.16000.21000.24000.25000.22380.24600.25350.24110.25670.26210.25680.26760.27130.26760.27540.27820.
7、27130.27820.28070.26760.27540.27820.25680.26760.27130.24110.25670.26210.22380.24600.25350.21000.24000.25000.24000.21000.16000.24600.22380.18810.25670.24110.21710.26760.25680.24110.27540.26760.25670.27820.27130.26210.27540.26760.25670.26760.25680.24110.25670.241
8、10.21710.24600.22380.18810.24000.21000.1600Columns10through110.09000.14160.18810.22380.24600.25350.24600.22380.18810.14160.090000.09000.16000.21000.24000.25000.24000.21000.1
此文档下载收益归作者所有