I have the following code:
a=zeros(1,3);
syms x
y=zeros(1,3);
for j = 1:3
a = [zeros(1,j-1) 1 zeros(1,3-j)];
y(1,j)=x*a(1,j);
display(y(1,j));
end;
which I want to give me an array like [0 x 0]
for each iteration. But, on contrary, it gives me the following error:
The following error occurred converting from sym to double:
Error using mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.
Error in
Untitled123 (line 6)
y(1,j)=x*a(1,j);
Any suggestions?
The problem is that you allocated y
as a numeric (floating-point) array, not a symbolic one. a
is numeric, but when you multiply it by x
the result becomes symbolic. Because x
is a symbolic variable rather than a symbolic value, Matlab cannot perform the automatic cast back to double precision. You can allocate y
like this:
y = sym(zeros(1,3));