PDE heat equation one dimension
Show older comments
I solve the heat equation
m = 0;
x = linspace(0,1,20);
t = linspace(0,2,5);
u = sol(:,:,1);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
function [c,f,s] = pdex1pde(x,t,u,DuDx)
c = pi^2;
f = DuDx;
s = 0;
function u0 = pdex1ic(x)
u0 = sin(pi*x);
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = u1; %these two set k*dT/dx-q=0 on right side
ql = 0;
pr = pi*exp(-t);
qr = 1; %sets right side temperature to 0
there is error:Function definitions are not permitted in this context. on this line c = pi^2; I dont know why
Answers (1)
John D'Errico
on 6 Feb 2017
0 votes
This is a script. Functions are not allowed to be defined as m-files, INSIDE a script.
Save the function pdex1pde as a separate m-file.
Categories
Find more on PDE Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!