差分格式脚本文件:

 tic;
clear
clc
M=32;%x的步数
N=16;%y的步数
h1=1/M;%x的步长
h2=1/N;%y的步长
x=0:h1:1;
y=0:h2:1;
u=zeros(M+1,N+1);%给数值解分配内存单元
U=u;%给精确解分配内存单元
u(1,:)=y.^3;%y边值
u(M+1,:)=1+y.^3;%y边值
u(:,1)=x.^3;%x边值。uo
u(:,N+1)=1+x.^3;%x边值。un
for i=1:M+1
for j=1:N+1
Accurate(i,j)=x(i)^3+y(j)^3;%精确解
end
end
fun=inline('-6*(x+y)','x','y');
for i=1:M-1
for j=1:N-1
f(i,j)=fun(x(i+1),y(j+1));
end
end
Numerical=u;
error=eye(M+1,N+1);
while norm(error,inf) >= 1e-5
for i=2:M
for j=2:N
Numerical(i,j)=(f(i-1,j-1)+N^2*u(i,j-1)+M^2*u(i-1,j)+M^2*u(i+1,j)+N^2*u(i,j+1))/(2*M^2+2*N^2);
end
end
error=Numerical-u;
u=Numerical;
end
[X,Y]=meshgrid(x,y);
subplot(1,3,1)
mesh(X,Y,Numerical');
title('the image of Numerical solution')
xlabel('x');ylabel('y');zlabel('u');
subplot(1,3,2)
mesh(X,Y,Accurate');
title('the image of Accurate solution')
xlabel('x');ylabel('y');zlabel('U');
subplot(1,3,3)
mesh(X,Y,(Numerical-Accurate)');
title('the image of error solution')
xlabel('x');ylabel('y');zlabel('error');
toc;

效果图:

紧差分格式:

 tic;
clear
clc
M=100;%x的步数
N=100;%y的步数
h1=1/M;%x的步长
h2=1/N;%y的步长
x=0:h1:1;
y=0:h2:1;
u=zeros(M+1,N+1);%给数值解分配内存单元
U=u;%给精确解分配内存单元
u(1,:)=y.^3;%y边值
u(M+1,:)=1+y.^3;%y边值
u(:,1)=x.^3;%x边值。uo
u(:,N+1)=1+x.^3;%x边值。un
for i=1:M+1
for j=1:N+1
Accurate(i,j)=x(i)^3+y(j)^3;%精确解
end
end
b1=5/3*(M^2+N^2);
b2=1/6*(5*M^2-N^2);
b3=1/6*(5*N^2-M^2);
f=inline('-6*(x+y)','x','y');
for i=1:M-1
for j=1:N-1
ABf(i,j)=(1/144)*(f(x(i),y(j))+10*f(x(i),y(j+1))+f(x(i),y(j+2))...
+10*f(x(i+1),y(j))+100*f(x(i+1),y(j+1))+10*f(x(i+1),y(j+2))...
+f(x(i+2),y(j))+10*f(x(i+2),y(j+1))+f(x(i+2),y(j+2)));
end
end
Numerical=u;
error=eye(M+1,N+1);
while norm(error,inf) >= 1e-10
for i=2:M
for j=2:N
Numerical(i,j)=(ABf(i-1,j-1)+1/20*b1*Numerical(i-1,j-1)+b3*Numerical(i,j-1)+1/20*b1*Numerical(i+1,j-1)...
+b2*Numerical(i-1,j)+b2*u(i+1,j)...
+1/20*b1*u(i-1,j+1)+b3*u(i,j+1)+1/20*b1*u(i+1,j+1))/b1;
end
end
error=Numerical-u;
u=Numerical;
end
[X,Y]=meshgrid(x,y);
subplot(1,3,1)
mesh(X,Y,Numerical');
title('the image of Numerical solution')
xlabel('x');ylabel('y');zlabel('u');
subplot(1,3,2)
mesh(X,Y,Accurate');
title('the image of Accurate solution')
xlabel('x');ylabel('y');zlabel('U');
subplot(1,3,3)
mesh(X,Y,(Numerical-Accurate)');
title('the image of error solution')
xlabel('x');ylabel('y');zlabel('error');
toc;

效果图:

Matlab:五点差分方法求解椭圆方程非导数边值问题的更多相关文章

  1. Matlab:Crank Nicolson方法求解线性抛物方程

    tic; clear clc M=[,,,,,,];%x的步数 K=M; %时间t的步数 :length(M) hx=/M(p); ht=/K(p); r=ht/hx^; %网格比 x=:hx:; t ...

  2. Matlab:椭圆方程的导数边值问题

    tic; clear clc N=; M=*N; h1=/M; h2=/N; x=:h1:; y=:h2:; fun=inline('exp(x)*sin(pi*y)','x','y'); f=inl ...

  3. 【matlab】MATLAB程序调试方法和过程

    3.8  MATLAB程序的调试和优化 在MATLAB的程序调试过程中,不仅要求程序能够满足设计者的设计需求,而且还要求程序调试能够优化程序的性能,这样使得程序调试有时比程序设计更为复杂.MATLAB ...

  4. Complete the sequence! POJ - 1398 差分方法找数列规律

    参考链接:http://rchardx.is-programmer.com/posts/16142.html vj题目链接:https://vjudge.net/contest/273000#stat ...

  5. FESTUNG — 3. 采用 HDG 方法求解对流问题

    FESTUNG - 3. 采用 HDG 方法求解对流问题[1] 1. 控制方程 线性对流问题控制方程为 \[\begin{array}{ll} \partial_t c + \nabla \cdot ...

  6. 彻底理解了call()方法,apply()方法和bind()方法

    javascript中的每一个作用域中都有一个this对象,它代表的是调用函数的对象.在全局作用域中,this代表的是全局对象(在web浏览器中指的是window).如果包含this的函数是一个对象的 ...

  7. C语言多种方法求解字符串编辑距离问题的代码

    把做工程过程经常用的内容记录起来,如下内容段是关于C语言多种方法求解字符串编辑距离问题的内容. { if(xbeg > xend) { if(ybeg > yend) return 0; ...

  8. 三种初步简易的方法求解数值问题 of C++

    1. “二分法解方程” 在二分法中,从区间[a,b]开始,用函数值f(a)与f(b)拥有相反的符号.如果f在这个区间连续,则f的图像至少在x=a,x=b之间穿越x轴一次,因此方程f(x)=0在[a,b ...

  9. Minimum_Window_Substring两种方法求解

    题目描述: Given a string S and a string T, find the minimum window in S which will contain all the chara ...

随机推荐

  1. daemon函数详解

    https://blog.csdn.net/xinyuan510214/article/details/50903280

  2. soapui调用redis,获取短信验证码

    1.首先,调用redis需要引入redis的jar包,放入到soapui指定目录中,例如我的目录D:\Program Files\SmartBear\SoapUI-Pro-5.1.2\bin\ext ...

  3. JDBC最原始的代码做查询操作

    首先编写一个User类. public class User { private String username; private String password; public String get ...

  4. jenkins使用笔记

    jenkins动态在构建的时候给脚本传递参数 1.任务  >General > 参数化构建过程 >选项参数 2.把变量传递给shell脚本 3.构建的时候给参数赋值 4.shell脚 ...

  5. 数据库连接池 maxActive,maxIdle,maxWait参数

    maxActive 连接池支持的最大连接数,这里取值为20,表示同时最多有20个数据库连接.设 0 为没有限制.maxIdle 连接池中最多可空闲maxIdle个连接 ,这里取值为20,表示即使没有数 ...

  6. 关于Oracle 10.2.0.5 版本应用SCN补丁14121009相关问题

    环境:OEL 5.7 + Oracle 10.2.0.5 背景:Oracle发布的两篇关于2019年6月份将自动调整高版本数据库的SCN COMPATIBILITY的MOS文章引起了很多客户的恐慌,尤 ...

  7. redis示例 - 限速器,计时器

    INCR INCR key 将 key 中储存的数字值增一. 如果 key 不存在,那么 key 的值会先被初始化为 0 ,然后再执行 INCR 操作. 如果值包含错误的类型,或字符串类型的值不能表示 ...

  8. Poj3984 迷宫问题 (BFS + 路径还原)

    Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, ...

  9. GoldenGate12.3中新增的Parallel Replicat (PR)介绍

    Parallel Replicat介绍 在OGG 12.3.0.1中新增的一项特性parallel replicat(并行投递),相对于传统的投递和集成投递(integrated replicat), ...

  10. 怎样从外网访问内网DB2数据库

    外网访问内网DB2数据库 本地安装了DB2数据库,只能在局域网内访问,怎样从外网也能访问本地DB2数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动DB2数据库 默认安装的DB2 ...