资源简介
该程序采用有限差分方法(隐式和显式)仿真了一维和二维域扩散方程。该程序采用有限差分方法(隐式和显式)仿真了一维和二维域扩散方程。该程序采用有限差分方法(隐式和显式)仿真了一维和二维域扩散方程。
代码片段和文件信息
% Simulating the 1-D Diffusion equation (Fourier‘s equation) by the
...Finite Difference Method(a time march)
% Numerical scheme used is a first order upwind in time and a second order
...central difference in space (both Implicit and Explicit)
%%
%Specifying Parameters
nx=50; %Number of steps in space(x)
nt=30; %Number of time steps
dt=0.1; %Width of each time step
dx=2/(nx-1); %Width of space step
x=0:dx:2; %Range of x (02) and specifying the grid points
u=zeros(nx1); %Preallocating u
un=zeros(nx1); %Preallocating un
vis=0.01; %Diffusion coefficient/viscosity
beta=vis*dt/(dx*dx); %Stability criterion (0<=beta<=0.5 for explicit)
UL=1; %Left Dirichlet B.C
UR=1; %Right Dirichlet B.C
UnL=1; %Left Neumann B.C (du/dn=UnL)
UnR=1; %Right Neumann B.C (du/dn=UnR)
%%
%Initial Conditions: A square wave
for i=1:nx
if ((0.75<=x(i))&&(x(i)<=1.25))
u(i)=2;
else
u(i)=1;
end
end
%%
%B.C vector
bc=zeros(nx-21);
bc(1)=vis*dt*UL/dx^2; bc(nx-2)=vis*dt*UR/dx^2; %Dirichlet B.Cs
%bc(1)=-UnL*vis*dt/dx; bc(nx-2)=UnR*vis*dt/dx; %Neumann B.Cs
%Calculating the coefficient matrix for the implicit scheme
E=sparse(2:nx-21:nx-31nx-2nx-2);
A=E+E‘-2*speye(nx-2); %Dirichlet B.Cs
%A(11)=-1; A(nx-2nx-2)=-1; %Neumann B.Cs
D=speye(nx-2)-(vis*dt/dx^2)*A;
%%
%Calculating the velocity profile for each time step
i=2:nx-1;
for it=0:nt
un=u;
disp(u)
h=plot(xu); %plotting the velocity profile
axis([0 2 0 3])
title({[‘1-D Diffusion with \nu =‘num2str(vis)‘ and \beta = ‘num2str(beta)];[‘time(\itt) = ‘num2str(dt*it)]})
xlabel(‘Spatial co-ordinate (x) \rightarrow‘)
ylabel(‘Transport property profile (u) \rightarrow‘)
drawnow;
refreshdata(h)
%Uncomment as necessary
%-------------------
%Implicit solution
U=un;U(1)=[];U(end)=[];
U=U+bc;
U=D\U;
u=[UL;U;UR]; %Dirichlet
%u=[U(1)-UnL*dx;U;U(end)+UnR*dx]; %Neumann
%}
%-------------------
%Explicit method with F.D in time and C.D in space
%{
u(i)=un(i)+(vis*dt*(un(i+1)-2*un(i)+un(i-1))/(dx*dx));
%}
end 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2327 2018-10-10 11:06 Diffusion\Diffusion_1D.m
文件 3827 2018-10-10 11:44 Diffusion\Diffusion_2D.m
文件 1110 2018-08-24 10:47 Diffusion\Intro.txt
文件 1334 2018-08-24 10:45 Diffusion\license.txt
- 上一篇:双树复小波
- 下一篇:GA遗传算法改进BP神经网络
相关资源
- 串行级联cpm系统MATLAB仿真
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
川公网安备 51152502000135号
评论
共有 条评论