How to for loop a summation yielding different matrix values

I am trying to write a for loop for a sum expression as follows:
I don't intend to automate the ij portion of it. I only have ij = 11 and ij = 22 so I can just insert 2 expressions (2 identical loops) with the values for Q_11 and Q_22.
The z aspect of my function are thicknesses that may vary and I can define prior to the loop.
I do need a little help with the iteration part of the loop since my knowledge of for loops is VERY basic.

4 Comments

What code did you try? And have you completed a basic Matlab tutorial?
Hey Rik,
I have done a few tutorials and learned a bit of C++ before touching matlab.
The issue Im having trouble figuring out is alternating my sum. What I mean is that my Qij above actually are different 3x3 matrices (which I have saved to zeros variables). However, for example, in my sum, each z gets multiplied by Q_11 from one matrix, then Q_11 from the other matrix, etc. So it alternates for as many Zs as there are. For 11, 12, 22, and 66 it doesn't matter since my matrices are identical for those values, but for 16 and 26, the sign changes. I tried doing a (-1)^N symsum to alternate them but this doesn't really help me for all of my cases. Below in the photo I show how the Qij values alternate in the sum.
I'd appreciate some guidance on this if you have an idea! Thank you!
This is currently what I have (I excluded all of my formulas to calculate Qbs):
%B Matrix%
for l=1:LN
zB(l) = z(l+1)^2-z(l)^2;
end
B11 = .5*sum(Qb11(1,1).*(zB));
B12 = .5*sum(Qb12(1,1).*(zB));
B22 = .5*sum(Qb22(1,1).*(zB));
B66 = .5*sum(Qb66(1,1).*(zB));
B16 = .5*sum(Qb16(1,1).*(zB));
B26 = .5*sum(Qb26(1,1).*(zB));
%This is what I'm trying to accomplish, but in a loop so I can have any number of Zs:
B11 = .5(Qb11(1,1).*(zB(1)) + Qb11(1,2).*(zB(2)+Qb11(1,1).*(zB(3)+Qb11(1,2).*(zB(4));
%This performs the operation above but without alternating between Qb(1,1) and Qb(1,2)
Why aren't you storing B and Qb in arrays? That would make it much easier to write a loop.
Do you mean like this? I had it like this before but I wasn't able to come up with a solution.
EDIT: I think I see where you are leading me. See the second part of the code below, I modified it. So now I just need to figure out how to alternate these values to pull from different matrices.
%B MATRIX%
for l=1:LN
zB(l) = z(l+1)^2-z(l)^2;
end
B = zeros(3,3); %GPa-mm^2
B(1,1) = .5*sum(Qb(1,1).*(zB));
B(1,2) = .5*sum(Qb(1,2).*(zB));
B(2,2) = .5*sum(Qb(2,2).*(zB));
B(3,3) = .5*sum(Qb(3,3).*(zB));
B(1,3) = .5*sum(Qb(1,3).*(zB));
B(2,3) = .5*sum(Qb(2,3).*(zB));
%-----Updated--------
%A,B,D MATRIX%
for k=1:LN
zA(k) = z(k+1)-z(k);
end
for l=1:LN
zB(l) = z(l+1)^2-z(l)^2;
end
for m=1:LN
zD(m) = z(m+1)^3-z(m)^3;
end
for i = 1:3
for j = 1:3
A(i,j) = sum(Qb(i,j).*(zA));
B(i,j) = (1/2)*sum(Qb(i,j).*(zB));
D(i,j) = (1/3)*sum(Qb(i,j).*(zD));
end
end
A
B
D

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Tags

Asked:

on 31 Oct 2020

Edited:

on 9 Nov 2020

Community Treasure Hunt

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

Start Hunting!