For loop expansion summation

3 vues (au cours des 30 derniers jours)
Valeria Garcia
Valeria Garcia le 14 Juil 2015
Hello I'm writing a code that expands a summation and I'm doing it in a for loop. This is for a much more complicated problem that I'm doing but I want to check it. My code seems to "work" in the bigger problem but It's giving me different results than when put the expanded summations. I'm trying to check the loop in a different file but It's not working.
This is what I have in the other file.
%%Constants and Parameters
syms y1 y2 y3 y4
y=[y1 y2 y3 y4];
g = zeros(3,3,3,3);
for m = 0:2
for i = 0:2
for j = 0:2
for k = 0:2
g(m+1,i+1,j+1,k+1) = integral(@(z)Modeshape2t(m,i,j,k,z),0,1);
end
end
end
end
%%A Matrix
m=2;
i=2;
A=zeros(m,i);
for m=1:2;
for i=1:2;
A(m,i)= g(m+1,i+1,0+1,0+1);
for j=1:2;
A(m,i) = A(m,i) -2*y(j*2-1,:)*g(m+1,i+1,j+1,0+1);
for k=1:2;
A(m,i) = A(m,i) + y(j*2-1,:).*y(k*2-1,:)*g(m+1,i+1,j+1,k+1);
end
end
end
end
%%B Vector
m=2;
B=zeros(m);
for m=1:2;
B(m)= delta*Vt^2*(f+1)*g(m+1,0+1,0+1,0+1);
for i=1:2;
B(m)=B(m)-(w(m)^2.*y(2*i-1,:)*A(m,i)+b*y(2i,:)*A(m,i)+f*Vt^2*delta*y(2*i-1,:)*g(m+1,i+1,0+1,0+1));
end
end
This is the error text I get:
*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 Untitled (line 27) A(m,i) = A(m,i) -2*y(j*2-1,:)*g(m+1,i+1,j+1,0+1);*
I don't know what that means or how to fix it. I just want to see if I get the whole expanded functions I want.

Réponses (1)

Muthu Annamalai
Muthu Annamalai le 14 Juil 2015
Modifié(e) : Muthu Annamalai le 14 Juil 2015
It seems to me you are trying to write a tensor like summation; you will be well advised to use matrix products by re-arranging your computation.
For a matrix A and vector x you get a "summation" by calculating the product, A*x
In your case you are somehow triggering the errors of symbolic toolbox functions, http://www.mathworks.com/help/symbolic/mupad-engine-commands.html ; this maybe something to do with your integrate() call, and possibly nothing wrong with your nested for-loops.
HTH

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by