how to define a vector of functions using a for cycle?

4 ビュー (過去 30 日間)
Luca Losero
Luca Losero 2019 年 10 月 10 日
コメント済み: Luca Losero 2019 年 10 月 16 日
I have defined n functions fi(t,x,y),
I want to obtain the vector:
F=@(t,x,y) [f1(t,x,y); f2(t,x,y); ... fn(t,x,y)],
without writing the vector by hand but implementing a cycle like:
for i=1:n
fi=@(t,x,y) x+3*i*y+t^2
F(i)=fi
end
  3 件のコメント
Shubham Gupta
Shubham Gupta 2019 年 10 月 10 日
Maybe this will help?
F = @(t,x,y)[];
for i=1:n
fi=@(t,x,y) x+3*i*y+t^2
F=@(t,x,y)[F(t,x,y);fi(t,x,y)];
end
Luca Losero
Luca Losero 2019 年 10 月 16 日
thanks a lot, with your help I solved it

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

採用された回答

Shivam Prasad
Shivam Prasad 2019 年 10 月 16 日
編集済み: Shivam Prasad 2019 年 10 月 16 日
Hi Luca,
Check if this works for you:
syms t x y
n=5; % define a n
F=matlabFunction(subs(x+3*i*y+t^2,i,1:n))

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by