Error: Function definitions are not permitted in this context.
Mostra commenti meno recenti
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 Commento
Image Analyst
il 13 Nov 2018
Exactly HOW did you try to execute it? You didn't just click the green run triangle without passing in agruments did you?
Risposte (2)
madhan ravi
il 13 Nov 2018
Modificato: madhan ravi
il 14 Nov 2018
0 voti
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 Commento
madhan ravi
il 14 Nov 2018
Modificato: madhan ravi
il 14 Nov 2018
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
il 13 Nov 2018
0 voti
Categorie
Scopri di più su Introduction to Installation and Licensing in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!