Why this code does not run?

Hi, I am trying to learn how to solve PDEs. Here is the example from MatLab itself. But it did not run. I dont know what is missing . Anyone can help? thanks Ming
[Edit SCd: code formatting]
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 = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
x = linspace(0,1,20);
t = linspace(0,2,5);
m = 0;
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
u = sol(:,:,1);
surf(x,t,u)

댓글 수: 3

Jan
Jan 2011년 10월 6일
"It did not run" dows not contain enough information to understand the cause of the problem. Do you get an error message? How do you cal the function?
sunnoom
sunnoom 2011년 10월 6일
thank for comment. The error message was:
Input argument "DuDx" is undefined.
Error in ==> pdex1pde at 3
f = DuDx;
Thanks
Walter Roberson
Walter Roberson 2011년 10월 6일
That does sound odd.
I would put a breakpoint in that routine at the first line, and would check to see what parameters did get passed and their sizes.

댓글을 달려면 로그인하십시오.

답변 (3개)

Jan
Jan 2011년 10월 6일

0 개 추천

"function [c,f,s] = pdex1pde(x,t,u,DuDx)" means, that you have to call the function pdex1pde with 4 input arguments. Did you call it manually without inputs?
Wayne King
Wayne King 2011년 10월 6일

0 개 추천

Hi, Just enter
>> pdex1
at the command prompt, that will run the demo.

댓글 수: 1

sunnoom
sunnoom 2011년 10월 6일
yes, that can run the demo, but I want to know the code.

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2011년 10월 7일

0 개 추천

Where you have written
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
x = linspace(0,1,20);
t = linspace(0,2,5);
m = 0;
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
u = sol(:,:,1);
surf(x,t,u)
You need to break this up in to two parts:
function [pl,ql,pr,qr] = pdex1bc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi * exp(-t);
qr = 1;
function sol = runpde
x = linspace(0,1,20);
t = linspace(0,2,5);
m = 0;
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
u = sol(:,:,1);
surf(x,t,u)
and that new function needs to go first in the file if you are putting all of the routines in the same file.

질문:

2011년 10월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by