Error: Function definitions are not permitted in this context.

I am using pdepe example given in your page https://www.mathworks.com/help/matlab/ref/pdepe.html
On executing the code, following error message appears, even though the output is obtained.
function [c,f,s] = pdex1pde(x,t,u,DuDx)
Error: Function definitions are not permitted in this context.
MATLAB Version: 9.3.0.948333 (R2017b) Update 9
MATLAB License Number: 1110***
Operating System: Mac OS X Version: 10.13.6 Build: 17G65
Java Version: Java 1.8.0_144-b01 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
=========================================
m = 0;
x = linspace(0,1,20);
t = linspace(0,2,5);
sol = pdepe(m,@pdex1pde,@pdex1ic,@pdex1bc,x,t);
% Extract the first solution component as u.
u = sol(:,:,1);
% A surface plot is often a good way to study a solution.
surf(x,t,u)
title('Numerical solution computed with 20 mesh points.')
xlabel('Distance x')
ylabel('Time t')
% A solution profile can also be illuminating.
figure
plot(x,u(end,:))
title('Solution at t = 2')
xlabel('Distance x')
ylabel('u(x,2)')
% --------------------------------------------------------------
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;

댓글 수: 1

Exactly HOW did you try to execute it? You didn't just click the green run triangle without passing in agruments did you?

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

답변 (2개)

madhan ravi
madhan ravi 2018년 11월 13일
편집: madhan ravi 2018년 11월 14일

0 개 추천

You can‘t run a code which has function in command window. See https://www.mathworks.com/help/matlab/matlab_prog/calling-functions.html to avoid errors while calling a function.

댓글 수: 1

madhan ravi
madhan ravi 2018년 11월 14일
편집: madhan ravi 2018년 11월 14일
in the latter versions you can even run the function in the command window but you need to pass arguments before calling a function.

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

Satinder Virdi
Satinder Virdi 2018년 11월 13일

0 개 추천

Thank you for the clue, I am able to understand now.
The functions need to be in the script file and called into the command window, for execution.

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

질문:

2018년 11월 13일

편집:

2018년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by