matlab求解二维泊松方程,MATLAB编程求解二维泊松方程

《MATLAB编程求解二维泊松方程》由会员分享,可在线阅读,更多相关《MATLAB编程求解二维泊松方程(3页珍藏版)》请在读根文库上搜索。

1、% 真解 u=sin(pi*x)*sin(pi*y) % 方程 -Laplace(u)=f % f=2*pi2*sin(pi*x)*sin(pi*y) %difference code for elliptic equations with constant coefficient %clear all%clcN=20;h=1/N;S=h2;x=0:h:1;y=0:h:1;% Stiff matrix A=zeros(N-1)2,(N-1)2);for i=1A(i,i)=4/h2;A(i,i+1)=-1/h2;A(i,i+(N-1)=-1/h2;endfor i=N-1A(i,i-1)=-1。

2、/h2;A(i,i)=4/h2;A(i,2*i)=-1/h2; %A(i,i+(N-1)=-1/h2endfor i=(N-2)*(N-1)+1A(i,i-(N-1)=-1/h2;A(i,i)=4/h2;A(i,i+1)=-1/h2;endfor i=(N-1)2A(i,i-(N-1)=-1/h2;A(i,i)=4/h2;A(i,i-1)=-1/h2;endfor n=2:N-2i=(N-2)*(N-1)+n;A(i,i-(N-1)=-1/h2;A(i,i-1)=-1/h2;A(i,i)=4/h2;A(i,i+1)=-1/h2;endfor i=2:N-2A(i,i-1)=-1/h2;A(i,。

3、i)=4/h2;A(i,i+1)=-1/h2;A(i,i+(N-1)=-1/h2;endfor m=1:N-3i=m*(N-1)+1;A(i,i-(N-1)=-1/h2;A(i,i)=4/h2;A(i,i+1)=-1/h2;A(i,i+(N-1)=-1/h2;endfor m=2:N-2i=m*(N-1);A(i,i-(N-1)=-1/h2;A(i,i-1)=-1/h2;A(i,i)=4/h2;A(i,i+(N-1)=-1/h2;end% for m=1:N-3% i=m*(N-1)+(N-1);% A(i,i-(N-1)=-1/h2;% A(i,i-1)=-1/h2;% A(i,i)=4/h。

4、2;% A(i,i+(N-1)=-1/h2;% endfor m=1:N-3for n=2:N-2i=m*(N-1)+n;A(i,i-(N-1)=-1/h2;A(i,i-1)=-1/h2;A(i,i)=4/h2;A(i,i+1)=-1/h2;A(i,i+(N-1)=-1/h2;endend% Right termF=zeros(N-1)2,1);for m=0:N-2for n=1:N-1i=m*(N-1)+n;F(i)=2*pi2*sin(pi*n*h)*sin(pi*(m+1)*h);endend%U=zeros(N-1)2,1);u1=AF; u=zeros(N+1)2,1);for m。

5、=1:N-1u(m*(N+1)+2:m*(N+1)+N)=u1(m-1)*(N-1)+1:m*(N-1);endU=zeros(N+1,N+1);for m=1:N+1U(m,:)=u(m-1)*(N+1)+1:m*(N+1);endsurf(x,y,U)u_exact=zeros(N+1)2,1);for m=0:Nfor n=1:N+1i=m*(N+1)+n;u_exact(i)=sin(pi*n*h)*sin(pi*m*h);endendU_exact=reshape(u_exact,N+1,N+1);subplot(1,2,)err=max(abs(u-u_exact);l2_err=norm(u-u_exact)*h;errl2_err。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值