Unable to perform assignment because value of type 'sym' is not convertible to 'double'.
Caused by: Error using mupadengine/feval2char Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values for variables.
Dynamically defining variables is not a good idea, as you have done here -
syms u10 u9 u8 u7 u6 u5 u4 u3 u2 u1;
syms x10 x9 x8 x7 x6 x5 x4 x3 x2 x1;
syms y10 y9 y8 y7 y6 y5 y4 y3 y2 y1;
and here -
u=[];x=[];y=[];
for j=1:1:t+1
u = [u; sym(['u' num2str(j)])];
x = [x; sym(['x' num2str(j)])];
y = [y; sym(['y' num2str(j)])];
end
A better method is to define a symbolic array like this, so that you can define all of them in a single command (as I have done below) -
syms u [1 10]
u
u =
And use indexing to access the individual variables -
u(1)
ans =
%Define them collectively in a single command
syms u x y [1 10]
As for the error occuring in the 2nd for loop, it is not clear to me what the objective is or what you want to do, thus I can not suggest anything other than correcting the size of preallocated variable.
Thank you for the symbolic command that simplifies the expression, but did not solve the problem. The problem is in looping since I cannot compile for t equal to 5, for example.