how to insert a function into anonymous function

1 回表示 (過去 30 日間)
Ani Asoyan
Ani Asoyan 2020 年 1 月 31 日
コメント済み: Star Strider 2020 年 1 月 31 日
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 ?

採用された回答

Star Strider
Star Strider 2020 年 1 月 31 日
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 件のコメント
Ani Asoyan
Ani Asoyan 2020 年 1 月 31 日
Thank you !
Star Strider
Star Strider 2020 年 1 月 31 日
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.)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by