How to put a function in another function?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yusuke Nakamura
am 21 Mär. 2016
Kommentiert: Yusuke Nakamura
am 21 Mär. 2016
For instance, if there are two functions which are with respect to x: f(x) = x^2 and g(x) = 4*x, I want to make another function using them: h(x) = (f(x)+5*g(x))/(2*f(x)*g(x))
But,
f = @(x) x^2;
g = @(x) 4*x;
h = @(x) (f+5*g)/(2*f*g);
doesn't work.
Is there any way to do this?
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 21 Mär. 2016
Yusuke - if x is the input parameter to your function h, then you must pass this into f and g as well. So instead of
h = @(x) (f+5*g)/(2*f*g);
you would write
h = @(x) (f(x)+5*g(x))/(2*f(x)*g(x));
Try the above and see what happens!
Weitere Antworten (1)
the cyclist
am 21 Mär. 2016
You have to supply the function arguments:
h = @(x) (f(x)+5*g(x))/(2*f(x)*g(x));
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!