For loop with symbolic expressions

I am trying to make a for loop that put symbolic expressions inside a matrix ( in positions given by index of for loop) and i get this 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.
Can you help me ?
Thanks in advance,

2 comentarios

sixwwwwww
sixwwwwww el 10 de Oct. de 2013
Can you please share your code to locate the error?
rodrigo
rodrigo el 10 de Oct. de 2013
Yes, my code is above:
%%%%%%%%%%%%%%%%%%%%%%%%%
k=1; matriz_incognitas=zeros(6+4*k,1);
syms x syms theta L=2
Ni=1-(x/L) Nj=x/L
matriz_N=zeros(3,6+4*k);
for m=1:k
matriz_N(1,4+m-1)= 0
matriz_N(1,4+m+k-1)=sprintf(Ni*cos(k+1)*theta
matriz_N(2,4+m-1)= -Ni*sin(k+1)*theta*(1/(k+1))
matriz_N(2,4+m+k-1)= 0
matriz_N(3,4+m-1)= Ni*cos(k+1)*theta
matriz_N(3,4+m+k-1)= 0
matriz_N(1,4+m-1)= 0
matriz_N(1,4+m+k-1)=Nj*cos(k+1)*theta
matriz_N(2,4+m-1)= -Nj*sin(k+1)*theta*(1/(k+1))
matriz_N(2,4+m+k-1)= 0
matriz_N(3,4+m-1)= Nj*cos(k+1)*theta
matriz_N(3,4+m+k-1)= 0
end
%%%%%%%%%%%%%%%%%%%%%%%%%%

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Oct. de 2013
Do not initialize the matrix to zeros(): that requires numeric values instead of symbolic.
Try
matriz_N = sym(zeros(3, 6+4*k));

Más respuestas (0)

Preguntada:

el 10 de Oct. de 2013

Respondida:

el 10 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by