Using an anonymous function handle as input into another function handle
Ältere Kommentare anzeigen
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,
Akzeptierte Antwort
Weitere Antworten (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
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

