I would like to write a single line code for ‘n’ number of functions.
For example (here ‘v’ and ‘theta’ are variables)
f(1)= v(1)cos(theta(1)); f(2)= v(2)cos(theta(2)); f(3)= v(3)cos(theta(3)); . . f(n)= v(n)cos(theta(n));
I wrote my code as
n=10; syms v theta for i=1:n f(i)= v(i)*cos(theta(i)); end
it gave the following errors
Index exceeds matrix dimensions.Error in sym/subsref (line 814) R_tilde = builtin('subsref',L_tilde,Idx);Error in Untitled2 (line 6)f(i)= v(i)*cos(theta(i));
Would appreciate your kind help.
Regards, Mustafa
Best Answer