Vectorial anonymous function, given its components as anonymous functions

3 ビュー (過去 30 日間)
Marco Asperti
Marco Asperti 2020 年 9 月 22 日
編集済み: Ameer Hamza 2020 年 9 月 22 日
Hello everybody,
I would like to create a vectorial anonymous function, building it up by simply "putting together" the functions corresponding to its elements (previously defined as scalar anonymous functions, of vectorial variable x). My aim is to create an anonymous function that, for instance, can be recognized by fsolve as a single anonymous function.
Here is an example:
g = @(x) x(1) + x(2).^2 ;
h = @(x) -2*x(1) + x(2).^3 ;
Now, I would like to create (formally): f(x) = [ g(x); h(x) ], without specifying it directly as:
f = @(x) [ x(1) + x(2).^2 ; -2*x(1) + x(2).^3 ] ;
but, rather, combining g and h previously defined, to end up with an anonymous function equivalent to f reported above (in such a way that, for instance, it can be fed to fsolve).
Any suggestion to do it?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 22 日
This will work
g = @(x) x(1) + x(2).^2 ;
h = @(x) -2*x(1) + x(2).^3 ;
f = @(x) [g(x); h(x)];
  2 件のコメント
Marco Asperti
Marco Asperti 2020 年 9 月 22 日
Oh as simple as that, I tried and of course it does the job. Thank you so much!
Ameer Hamza
Ameer Hamza 2020 年 9 月 22 日
編集済み: Ameer Hamza 2020 年 9 月 22 日
I am glad to be of help!!! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeThermal Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by