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

1 visualización (últimos 30 días)
Luca Losero
Luca Losero el 10 de Oct. de 2019
Comentada: Luca Losero el 16 de Oct. de 2019
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 comentarios
Shubham Gupta
Shubham Gupta el 10 de Oct. de 2019
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 el 16 de Oct. de 2019
thanks a lot, with your help I solved it

Iniciar sesión para comentar.

Respuesta aceptada

Shivam Prasad
Shivam Prasad el 16 de Oct. de 2019
Editada: Shivam Prasad el 16 de Oct. de 2019
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))

Más respuestas (0)

Categorías

Más información sobre Simscape Electrical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by