Matlab:五点差分方法求解椭圆方程非导数边值问题






差分格式脚本文件:
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:五点差分方法求解椭圆方程非导数边值问题的更多相关文章
- 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 ...
- 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 ...
- 【matlab】MATLAB程序调试方法和过程
3.8 MATLAB程序的调试和优化 在MATLAB的程序调试过程中,不仅要求程序能够满足设计者的设计需求,而且还要求程序调试能够优化程序的性能,这样使得程序调试有时比程序设计更为复杂.MATLAB ...
- Complete the sequence! POJ - 1398 差分方法找数列规律
参考链接:http://rchardx.is-programmer.com/posts/16142.html vj题目链接:https://vjudge.net/contest/273000#stat ...
- FESTUNG — 3. 采用 HDG 方法求解对流问题
FESTUNG - 3. 采用 HDG 方法求解对流问题[1] 1. 控制方程 线性对流问题控制方程为 \[\begin{array}{ll} \partial_t c + \nabla \cdot ...
- 彻底理解了call()方法,apply()方法和bind()方法
javascript中的每一个作用域中都有一个this对象,它代表的是调用函数的对象.在全局作用域中,this代表的是全局对象(在web浏览器中指的是window).如果包含this的函数是一个对象的 ...
- C语言多种方法求解字符串编辑距离问题的代码
把做工程过程经常用的内容记录起来,如下内容段是关于C语言多种方法求解字符串编辑距离问题的内容. { if(xbeg > xend) { if(ybeg > yend) return 0; ...
- 三种初步简易的方法求解数值问题 of C++
1. “二分法解方程” 在二分法中,从区间[a,b]开始,用函数值f(a)与f(b)拥有相反的符号.如果f在这个区间连续,则f的图像至少在x=a,x=b之间穿越x轴一次,因此方程f(x)=0在[a,b ...
- Minimum_Window_Substring两种方法求解
题目描述: Given a string S and a string T, find the minimum window in S which will contain all the chara ...
随机推荐
- Keras序列模型学习
转自:https://keras.io/zh/getting-started/sequential-model-guide/ 1.顺序模型是多个网络层的线性堆叠. 你可以通过将网络层实例的列表传递给 ...
- java之WebService
链接:https://www.jianshu.com/p/1c145315da47 WebService介绍 首先我们来谈一下为什么需要学习webService这样的一个技术吧.... 问题一 如果我 ...
- Linux文件系统的硬连接和软连接
title: Linux文件系统的硬连接和软连接 date: 2018-02-06T20:26:25+08:00 tags: ["文件系统"] categories: [" ...
- uva12545
#include<iostream> using namespace std; +; char s[maxn],t[maxn]; int main(){ //freopen("1 ...
- Hdu2039 三角形
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2039 三角形 Time Limit: 2000/1000 MS (Java/Others) Me ...
- P1636 Einstein学画画
一笔画问题 P1636 Einstein学画画 如果一个图存在一笔画,则一笔画的路径叫做欧拉路,如果最后又回到起点,那这个路径叫做欧拉回路. 奇点:跟这个点相邻的边数目有奇数个的点 不存在奇数个奇点的 ...
- Json的转换
package com.utils; import java.io.IOException; import java.util.List; import org.codehaus.jackson.Js ...
- Docker 构建镜像
Docker 构建镜像 1.首先,在项目的根目录下,新建一个文本文件.dockerignore,写入下面的内容. 下面三行代码表示: 1.这三个路径要排除,不要打包进入 image 文件. 2.如果你 ...
- Python imprt动态模块
1.解释器内部用的动态导入 directory_variable = __improt__("directory.filename") print(directory_variab ...
- Splay详解
平衡树实际很简单的 以下讲解都以Luogu P3369 [模板]普通平衡树为例 我不会带指针的Splay,所以我就写非指针型的Splay Splay是基于二叉查找树(bst)实现的 什么是二叉查找树呢 ...