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 ...
随机推荐
- NuGet Install-Package报错解决Package Manager Console error - PowerShell version 2.0 is not supported. Please upgrade PowerShell to 3.0 or greater and restart Visual Studio.
问题: Package Manager Console error - PowerShell version 2.0 is not supported. Please upgrade PowerShe ...
- iOS代理模式(delegate)的使用
前言: 代理模式是iOS中非常重要的一个模式,iOS SDK中的系统控件几乎都用到了代理模式.代理模式用来处理事件监听.参数传递功能. 协议创建(Protocol): 可手打如下代码,或者在代码块里面 ...
- Parallels Desktop 重装系统
安装教程,大家可以在网上找找 现在我想重装系统,怎么弄呢? 1.~/Documents/Parallels 目录下那个PVM后缀的文件直接删除 2.重装找开虚拟机,会弹出一个框,说找不到系统,点击删除 ...
- PHP----------用curl方式请求接口在同一个项目里面的时候不能请求的情况
1.环境是wnmp 2.NGINX中,看PHP文件块fastcig-pass的设置值(127.0.0.1:9000).设置都是以keepalive方式请求,接收到PHP文件时,交于后端过程PHPCGI ...
- php – Laravel 5查询关系导致“调用成员函数addEagerConstraints()on null”错误( 转载)
php – Laravel 5查询关系导致“调用成员函数addEagerConstraints()on null”错误 我一直在尝试创建一个简单的用户管理系统,但在查询关系时不断遇到障碍.例如,我 ...
- python模块化学习(一)
import time #获取cpu的时间: #获取本地时间: #获取标准时间格式: #获取时间戳: #print(time.clock()) #这个在3即将被舍弃 print(time.proces ...
- [Android] macOS的Android Studio快捷键
- 快速输入serialVersionUID - - 设置,左上角,Android Studio -> Preferences -> 搜索“Serializable class witho ...
- 21 python的魔法方法(转)
魔法方法 含义 基本的魔法方法 __new__(cls[, ...]) 1. __new__ 是在一个对象实例化的时候所调用的第一个方法2. 它的第一个参数是这个类,其他的参数是用来直接传递给 _ ...
- html5降龙十八掌-函数,对象,数组的练习
<script> function x1(){ var gj={}; gj.name="侯伟东"; gj.hp=500; ...
- 移动端picker插件
项目需要,要做移动端网页,比如选择出生日期什么的.可笑weui给的控件,竟然选择后的数据不准确. 于是自己写了一个. 链接: https://pan.baidu.com/s/1qY2SSxQ 密码: ...