Matlabで偏微分方程式を解く(非定常熱伝導)

以下を参考に。
www.mathworks.com

方程式の定義

以下の熱伝導方程式を解く
f:id:seinzumtode:20220311211544p:plain
上記を以下と比較し、パラメータm、f,、c、sを決定する。
f:id:seinzumtode:20220311211532p:plain
f:id:seinzumtode:20220311211640p:plain
コード(mはメインの関数で用いるのでここでは使わない)

function [c,f,s] = heatpde(x,t,u,dudx)
c = 1;
f = dudx;
s = 0;
end

初期条件(IC)の定義

f:id:seinzumtode:20220311211726p:plain
T0=0.5の場合のコード

function u0 = heatic(x)
u0 = 0.5;
end

境界条件(BC)の定義

f:id:seinzumtode:20220311212016p:plain
上記を下記と比較し、パラメータpとqを決定する。今回は境界条件が2組あるので、パラメータqとqも2組になる(それぞれ(pL,qL)、(pR,qR))。
f:id:seinzumtode:20220311211940p:plain
f:id:seinzumtode:20220311212031p:plain
よって、
f:id:seinzumtode:20220311212209p:plain

注意:パラメータfは上記の方程式の定義で決めている

function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = ur - 1;
qr = 0;
end

すべてまとめると以下になる。

clear; close all; clc;

L = 1;
x = linspace(0,L,20);
t = [linspace(0,0.05,20), linspace(0.5,5,10)];
m = 0;
sol = pdepe(m,@heatpde,@heatic,@heatbc,x,t);

colormap hot
imagesc(x,t,sol)
colorbar
xlabel('Distance x','interpreter','latex')
ylabel('Time t','interpreter','latex')
title('Heat Equation for $0 \le x \le 1$ and $0 \le t \le 5$','interpreter','latex')


function [c,f,s] = heatpde(x,t,u,dudx)
c = 1;
f = dudx;
s = 0;
end

function u0 = heatic(x)
u0 = 0.5;
end

function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = ur - 1;
qr = 0;
end

f:id:seinzumtode:20220311212306p:plain