how to insert a function into anonymous function

1 Ansicht (letzte 30 Tage)
Ani Asoyan
Ani Asoyan am 31 Jan. 2020
Kommentiert: Star Strider am 31 Jan. 2020
I have two functions
function a=f(x,y,z)
y=x.^2+5*y+z
end
and
b = @(x,y,z)(0.6*x+y.^3-z)
I want to insert the first one into the second (anonymous) one. for example
b = @(x,y,z)(0.6*x+y.^3-z+3*a)
how can I do that ?

Akzeptierte Antwort

Star Strider
Star Strider am 31 Jan. 2020
Call ‘f’ with the appropriate arguments:
b = @(x,y,z)(0.6*x+y.^3-z+3*f(x,y,z))
Note that ‘a’ is the output, ‘f’ is the function name.
  2 Kommentare
Ani Asoyan
Ani Asoyan am 31 Jan. 2020
Thank you !
Star Strider
Star Strider am 31 Jan. 2020
As always, my pleasure!
This works for single-output functions, because MATLAB always returns the first (or only) ouitput. For multiple-output functions, it would be necessary to evaluate them separately and then use the various outputs in the anonymous function. (They would be passed to the anonymous function as extra arguments.)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by