Using an anonymous function handle as input into another function handle
이전 댓글 표시
Hi there!
I have a question that's mostly about syntax: Let's say I write the anonymous function handle (for a program to give to ode45 to solve):
omega = @(t, y) ...
And then I want to use omega as input to the next function.
How come I have to input omega as omega(t, y)?
When I input just omega, without the (t, y), I get an error message about it being a function handle.
Is omega(t, y) a scalar quantity, while omega is a function handle?
Is it like specifying that omega takes two inputs t and y?
Another related question is:
Later, when I got to solve my odes, how can I evaluate omega at some time t and some value y?
Is it using the deval function?
Thanks so much in advance,
채택된 답변
추가 답변 (2개)
It has nothing to do with nesting of hte handles. If you don't call an anonymous function with inputs, it can't return anything numerical
f=@(t,y) t+y;
f(1,2) + 3
f + 3
Your premise is incorrect. The below example shows that it is valid to pass function handles between multiple levels
omega = @(t, y) cos(3*pi*y + t);
plotdriver(omega)
function plotdriver(g)
plotit(g, -10, 10, -1, 1)
end
function plotit(f, lb1, ub1, lb2, ub2)
fsurf(f, [lb1, ub1, lb2, ub2])
end
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

