Inserting functions in a vector function

14 ビュー (過去 30 日間)
Silvio
Silvio 2022 年 7 月 6 日
コメント済み: Silvio 2022 年 7 月 6 日
Hello. I have a code with this kind of structure:
g=@(X) ... (complex operations with a function 'X')
f=@(x) x;
for n=1:N
f=@(x) g(f(x));
end
After updating the function's form but before going to the next step of the cicle, I would like to store the updated function in a vector which is still a function. That is, I would like to create something like this:
for n=1:N
f=@(x) g(f(x));
v(n)=@(x) f(x)
end
I know that the syntax above is not correct. I wonder if there is any method to do that kind of operation.

採用された回答

Torsten
Torsten 2022 年 7 月 6 日
編集済み: Torsten 2022 年 7 月 6 日
g = @(x) x.^2;
f = @(x) x.^4;
for i = 1:3
f = @(x) g(f(x));
v{i} = f;
end
x = 4;
v{1}(x)
ans = 65536
v{2}(x)
ans = 4.2950e+09
v{3}(x)
ans = 1.8447e+19
  1 件のコメント
Silvio
Silvio 2022 年 7 月 6 日
Thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by