For loop expansion summation
4 views (last 30 days)
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);
A(m,i) = A(m,i) -2*y(j*2-1,:)*g(m+1,i+1,j+1,0+1);
A(m,i) = A(m,i) + y(j*2-1,:).*y(k*2-1,:)*g(m+1,i+1,j+1,k+1);
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.
Muthu Annamalai on 14 Jul 2015
Edited: Muthu Annamalai on 14 Jul 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.