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 件のコメント
Image Analyst
2018 年 11 月 13 日
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
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
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.
カテゴリ
ヘルプ センター および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!