1D Parabolic PDE (Heat Equation) with Crank-Nicholson method, MATLAB function pdepe()

  Рет қаралды 133

Charley Yang

Charley Yang

Күн бұрын

Пікірлер: 1
@WonYYang
@WonYYang 4 ай бұрын
Here is the MATLAB code for solving the heat equation as shown above. %em07e02.m clear, clf a=1; % The parameter of Eq.(E7.2.1) it0=@(x)sin(pi*x); % Initial condition bx0=@(t)0; bxf=@(t)0; % Boundary condition xf=1; M=25; tf=0.1; N=120; % r=0.625 [u_exp,x,t]=pde_heat_exp(a,xf,tf,it0,bx0,bxf,M,N); [u_imp,x,t]=pde_heat_imp(a,xf,tf,it0,bx0,bxf,M,N); % converge unconditionally [u_CN,x,t]=pde_heat_CN(a,xf,tf,it0,bx0,bxf,M,N); % converge unconditionally subplot(131), mesh(t,x,u_exp), set(gca,'fontsize',9) title('Numerical solution using pde heat exp()') xlabel('t[sec]'), ylabel('x[m]') subplot(132), mesh(t,x,u_CN), set(gca,'fontsize',9) title('Numerical solution using pde heat CN()') xlabel('t[sec]'), ylabel('x[m]') m=0; sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t); %u_pdepe = sol(:,:,1); % Extract the first solution component as u. u_pdepe = sol; % Extract the first solution component as u. % Analytical solution uo=@(x,t)sin(pi*x)*exp(-pi*pi*t); Uo= uo(x,t); aUo=abs(Uo)+eps; % Values of true analytical solution Nterm=10; [u_an,A,tt,xx]=pde_heat_ana(a,xf,tf,it0,M,N,Nterm); A %size(u_an), size(Uo) MN=M*N; err_an=norm((u_an-Uo)./aUo)/MN err_exp= norm((u_exp-Uo)./aUo)/MN err_imp= norm((u_imp-Uo)./aUo)/MN err_CN=norm((u_CN-Uo)./aUo)/MN err_pde=norm((u_pdepe.'-Uo)./aUo)/MN subplot(133), mesh(t,x,u_pdepe.') % surf(t,x,u) title('Numerical solution using pdepe()') set(gca,'fontsize',9), xlabel('t[sec]'), ylabel('x[m]') set(gcf,'color','white'), shg % -------------------------------------------------------------- function [c,f,s]=pdex1pde(x,t,u,DuDx) c=1; %1/a; f=DuDx; s=0; end function u0 = pdex1ic(x) u0=sin(pi*x); % Initial condition end function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t) pl=ul; ql=0; % Left boundary condition pr=ur; qr=0; % Right boundary condition end function [u,x,t]=pde_heat_CN(a,xf,tf,it0,bx0,bxf,M,N) % To solve a^2*u_xx = u_t for 0
Bayes theorem, the geometry of changing beliefs
15:11
3Blue1Brown
Рет қаралды 4,6 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
1% vs 100% #beatbox #tiktok
01:10
BeatboxJCOP
Рет қаралды 67 МЛН
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
MATLAB Analysis and PSpice Simulation of an OP amp Circuit
17:02
Why Does Diffusion Work Better than Auto-Regression?
20:18
Algorithmic Simplicity
Рет қаралды 430 М.
This open problem taught me what topology is
27:26
3Blue1Brown
Рет қаралды 1 МЛН
All Machine Learning algorithms explained in 17 min
16:30
Infinite Codes
Рет қаралды 520 М.
Everything You Need to Know About Control Theory
16:08
MATLAB
Рет қаралды 596 М.
I made maps that show time instead of space
10:44
Václav Volhejn
Рет қаралды 1,1 МЛН
Стыдные вопросы про Китай / вДудь
3:07:50
вДудь
Рет қаралды 5 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН