matlab PDE Modeler 导出解(附一个抛物线方程实例)

抛物线方程实例:

{ ∂ u ∂ t = ∂ 2 u ∂ x 2 u ( x , 0 ) = sin ⁡ ( π x ) u ( 0 , t ) = u ( 1 , t ) = 0 \left\{\begin{aligned} &\frac{\partial u}{\partial t}=\frac{\partial^2 u}{\partial x^2}\\ &u(x,0)=\sin(\pi x)\\ &u(0,t)=u(1,t)=0 \end{aligned}\right. tu=x22uu(x,0)=sin(πx)u(0,t)=u(1,t)=0

使用用户界面数值求解这个模型的过程网上有很多了,此处不再细讲。

但是关于如何导出这个解还是有话可说的。

首先先导出解 solve - export solution
matlab PDE Modeler 导出解(附一个抛物线方程实例)_第1张图片
观察这个解,发现这个解和我想象中的完全不一样。查询资料后发现:

导出的 u 的值的每一列表示一个时间状态(如果你的方程没有设置时间参数,那么应该只有一列),对于取定的一列的某一行的值,表示该 该节点在当前时间状态的值

这里的节点就是matlab细分求解区域的时候中得到的节点:
matlab PDE Modeler 导出解(附一个抛物线方程实例)_第2张图片
所以我们为了得到任意一点的函数值,我们应该根据这些节点的函数值,做插值计算,再求得想求解的一点的函数值。

导出节点的信息 Mesh - Export Mesh
matlab PDE Modeler 导出解(附一个抛物线方程实例)_第3张图片
其中 p 记录了节点的 x,y 坐标,其他的这里用不到。
matlab PDE Modeler 导出解(附一个抛物线方程实例)_第4张图片
于是,我们得到了节点的 x,y 坐标和函数值。下一步需要设置待求点,可以通过下面的代码设置。(以 x ∈ [ 0 , 1 ] , y ∈ [ − 0.5 , 0 ] x\in [0,1],y\in[-0.5,0] x[0,1],y[0.5,0])为例

xq = 0:0.01:1;
yq = -0.5:0.01:0;
[xx,yy] = meshgrid(xq,yq)

后面就是做插值,使用插值函数 griddata 即可。


附完整插值代码:

xq = 0:0.01:1;
yq = -0.5:0.01:0;
[xx,yy] = meshgrid(xq,yq)
x = p(1,:);
y = p(2,:);
v = u(:,end)'
vq = griddata(x,y,v,xx,yy)
plot(vq(1,:))
max(vq(1,:))

附 matlab pde modeler 代码


% This script is written and read by pdetool and should NOT be edited.
% There are two recommended alternatives:
% 1) Export the required variables from pdetool and create a MATLAB script
%    to perform operations on these.
% 2) Define the problem completely using a MATLAB script. See
%    https://www.mathworks.com/help/pde/examples.html for examples
%    of this approach.
function pdemodel
[pde_fig,ax]=pdeinit;
pdetool('appl_cb',1);
set(ax,'DataAspectRatio',[1 1 1]);
set(ax,'PlotBoxAspectRatio',[1.5 1 1]);
set(ax,'XLim',[-1.5 1.5]);
set(ax,'YLim',[-1 1]);
set(ax,'XTickMode','auto');
set(ax,'YTickMode','auto');

% Geometry description:
pderect([0 1 0 -0.5],'R1');
set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String','R1')

% Boundary conditions:
pdetool('changemode',0)
pdesetbd(4,...
'dir',...
1,...
'1',...
'0')
pdesetbd(3,...
'dir',...
1,...
'0',...
'0')
pdesetbd(2,...
'dir',...
1,...
'1',...
'0')
pdesetbd(1,...
'dir',...
1,...
'0',...
'0')

% Mesh generation:
setappdata(pde_fig,'Hgrad',1.3);
setappdata(pde_fig,'refinemethod','regular');
setappdata(pde_fig,'jiggle',char('on','mean',''));
setappdata(pde_fig,'MesherVersion','preR2013a');
pdetool('initmesh')
pdetool('refine')

% PDE coefficients:
pdeseteq(2,...
'1.0',...
'0',...
'0',...
'1.0',...
'0:0.001:0.3',...
'sin(pi*x)',...
'0.0',...
'[0 100]')
setappdata(pde_fig,'currparam',...
['1.0';...
'0  ';...
'0  ';...
'1.0'])

% Solve parameters:
setappdata(pde_fig,'solveparam',...
char('0','1000','10','pdeadworst',...
'0.5','longest','0','1E-4','','fixed','Inf'))

% Plotflags and user data strings:
setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 1 1 0 0 0 301 1 0 0 0 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');

% Solve PDE:
pdetool('solve')


2022年10月4日20:31

你可能感兴趣的:(MATLAB,matlab,偏微分方程)