MATLAB Answers

If i am trying to save each iteration of the matrix in a for loop to add them together at the end. How would I do that? I understand it will print each iteration of the matrix but I haven't figured out how to save each iteration and sum them all up.

3 views (last 30 days)
Scott Benson
Scott Benson on 9 Apr 2020
Answered: Star Strider on 9 Apr 2020
for N = 1:length(LayersInDegrees)
theta = LayersInDegrees(N);
m=cosd(theta);
n=sind(theta);
Q11=Q(1,1); Q12=Q(1,2); Q22=Q(2,2); Q66=Q(3,3);
QBar11= (Q11*(m^4))+ (2*(Q12+(2*Q66)))*(n^2)*(m^2) + (Q22*(n^4));
QBar12= ((Q11+Q22-(4*Q66))*(n^2)*(m^2)) + (Q12*((n^4)+(m^4)));
QBar16= ((Q11-Q12-2*(Q66))*(n)*(m^3)) + ((Q12-Q22+(2*(Q66)))*(n^3)*m);
QBar22= (Q11*(n^4)) + (2*(Q12+(2*(Q66)))*(n^2)*(m^2)) + Q22*(m^4);
QBar26= ((Q11-Q12-(2*(Q66)))*(n^3)*m) + (Q12-Q22+(2*(Q66)))*(n*(m^3));
QBar66= ((Q11+Q22-(2*(Q12))-(2*(Q66)))*(n^2)*(m^2))+ Q66*((n^4)+(m^4));
QBar =[QBar11 QBar12 QBar16; QBar12 QBar22 QBar26; QBar16 QBar26 QBar66];
disp(QBar/1e9)
end

  0 Comments

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 9 Apr 2020
I can’t run your code.
Try this:
QBar(:,:,N) =[QBar11 QBar12 QBar16; QBar12 QBar22 QBar26; QBar16 QBar26 QBar66];
To sum them:
sumQbar = sum(Qbar,3);

  0 Comments

Sign in to comment.

Sign in to answer this question.