Layered Composite Calculations - how to perform a loop to calculate the moment for each layer of a composite when the equation changes as each layer is added in?

So I am working on layered composites. I have already solved for sigma yy, sigma xx, and sigma xy for each layer. Now I'm trying to determine the moments of each layer which I have only been able to do manually instead of doing a loop for the whole thing which is now necessary as I'm getting into composites with hundreds of layers, not just 9. So if I can get the loop down for this 9 layered composite, hopefully I can manipulate it to work for a hundred layer one.
The sigma yy values for this 9-layered composite are:
sigyy =
25.1209 25.1209 -31.4011 -31.4011 25.1209 -31.4011 -31.4011 25.1209 25.1209
Here are the manual equations I have coded in to solve for the moments of each layer from top to bottom:
M1 = -sigyy(1)*1/2*h0^2;
M2 = -sigyy(1)*3/2*h0^2-sigyy(2)*1/2*h0^2;
M3 = -sigyy(1)*5/2*h0^2-sigyy(2)*3/2*h0^2-sigyy(3)*1/2*h0^2;
M4 = -sigyy(1)*7/2*h0^2-sigyy(2)*5/2*h0^2-sigyy(3)*3/2*h0^2-sigyy(4)*1/2*h0^2;
M5 = -sigyy(1)*9/2*h0^2-sigyy(2)*7/2*h0^2-sigyy(3)*5/2*h0^2-sigyy(4)*3/2*h0^2-sigyy(5)*1/2*h0^2;
M6 = -sigyy(1)*11/2*h0^2-sigyy(2)*9/2*h0^2-sigyy(3)*7/2*h0^2-sigyy(4)*5/2*h0^2-sigyy(5)*3/2*h0^2-sigyy(6)*1/2*h0^2;
M7 = -sigyy(1)*13/2*h0^2-sigyy(2)*11/2*h0^2-sigyy(3)*9/2*h0^2-sigyy(4)*7/2*h0^2-sigyy(5)*5/2*h0^2-sigyy(6)*3/2*h0^2-sigyy(7)*1/2*h0^2;
M8 = -sigyy(1)*15/2*h0^2-sigyy(2)*13/2*h0^2-sigyy(3)*11/2*h0^2-sigyy(4)*9/2*h0^2-sigyy(5)*7/2*h0^2-sigyy(6)*5/2*h0^2-sigyy(7)*3/2*h0^2-sigyy(8)*1/2*h0^2;
M9 = -sigyy(1)*17/2*h0^2-sigyy(2)*15/2*h0^2-sigyy(3)*13/2*h0^2-sigyy(4)*11/2*h0^2-sigyy(5)*9/2*h0^2-sigyy(6)*7/2*h0^2-sigyy(7)*5/2*h0^2-sigyy(8)*3/2*h0^2-sigyy(9)*1/2*h0^2;
This code also works to manually calculate the moments from the top to the bottom:
for i=1:9 % 1 to the number of layers
if (i==1)
M(i)=-sigyy(i)*0.5*h0^2;
end
if (i==2)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-1)*(0.5+(i-1))*h0^2;
M(i)=Mnew(i);
end
if (i==3)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-2)*(0.5+(i-1))*h0^2-sigyy(i-1)*(0.5+(i-2))*h0^2;
M(i)=Mnew(i);
end
if (i==4)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-3)*(0.5+(i-1))*h0^2-sigyy(i-2)*(0.5+(i-2))*h0^2-sigyy(i-1)*(0.5+(i-3))*h0^2;
M(i)=Mnew(i);
end
if (i==5)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-4)*(0.5+(i-1))*h0^2-sigyy(i-3)*(0.5+(i-2))*h0^2-sigyy(i-2)*(0.5+(i-3))*h0^2-sigyy(i-1)*(0.5+(i-4))*h0^2;
M(i)=Mnew(i);
end
if (i==6)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-5)*(0.5+(i-1))*h0^2-sigyy(i-4)*(0.5+(i-2))*h0^2-sigyy(i-3)*(0.5+(i-3))*h0^2-sigyy(i-2)*(0.5+(i-4))*h0^2-sigyy(i-1)*(0.5+(i-5))*h0^2;
M(i)=Mnew(i);
end
if (i==7)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-6)*(0.5+(i-1))*h0^2-sigyy(i-5)*(0.5+(i-2))*h0^2-sigyy(i-4)*(0.5+(i-3))*h0^2-sigyy(i-3)*(0.5+(i-4))*h0^2-sigyy(i-2)*(0.5+(i-5))*h0^2-sigyy(i-1)*(0.5+(i-6))*h0^2;
M(i)=Mnew(i);
end
if (i==8)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-7)*(0.5+(i-1))*h0^2-sigyy(i-6)*(0.5+(i-2))*h0^2-sigyy(i-5)*(0.5+(i-3))*h0^2-sigyy(i-4)*(0.5+(i-4))*h0^2-sigyy(i-3)*(0.5+(i-5))*h0^2-sigyy(i-2)*(0.5+(i-6))*h0^2-sigyy(i-1)*(0.5+(i-7))*h0^2;
M(i)=Mnew(i);
end
if (i==9)
M(i)=-sigyy(i)*0.5*h0^2;
Mnew(i)=M(i)-sigyy(i-8)*(0.5+(i-1))*h0^2-sigyy(i-7)*(0.5+(i-2))*h0^2-sigyy(i-6)*(0.5+(i-3))*h0^2-sigyy(i-5)*(0.5+(i-4))*h0^2-sigyy(i-4)*(0.5+(i-5))*h0^2-sigyy(i-3)*(0.5+(i-6))*h0^2-sigyy(i-2)*(0.5+(i-7))*h0^2-sigyy(i-1)*(0.5+(i-8))*h0^2;
M(i)=Mnew(i)
end
end
Here are what the moments should come out to be at the very end if the code and loop work (should always be symmetric and come back to zero in the last layer):
M =
-17.1470 -68.5880 -115.7423 -120.0291 -120.0291 -115.7423 -68.5880 -17.1470 0.0000
* Need to have a more concise and simple loop that will do all these calculations in a couple lines of code instead of manually coding each layer in *
Thank you for the help.

5 Commenti

Actually, it works fine for me. Look attached screen shot.
Oh I see, so I have to change r each time I want to get the corresponding M value, which is correct. Thank you!
However, I was hoping to run the code once and get all the Ms listed, from all the layers, so when I have a composite with 332 layers (my next one) I dont have to change the r and different values each time, for each layer. Any more suggestions? I'll keep playing around with your code.
I ended up manipulating it to this:
r=1:9;
k=2*r-1;
mom=0;
for i=1:9
part=-sigyy(i)*(k/2)*h0^2;
k=k-2;
mom=mom+part;
moments=mom(i)
end
And so far it is working, thank you so much! I've been working on this for weeks.
Hi again!
Yes now I saw it was some issue when I put r=1:1:9, I don't know what was happening. I am very happy that my code helps you.
I am actually quite new here. So I please you, that you accept my answer if it works fine.
Best of luck.

Accedi per commentare.

 Risposta accettata

If you have M(r):
k=2*r-1;
part=0;
mom=0;
for i=1:r
part=-siggy(i)*(k/2)*h0^2
k=k-2;
mom=mom+part
end

4 Commenti

What is r? When I try to run this I do not get the correct moment values
I define r as M(r), so if you have M7 then r=7.
the last 3 values of M are close but all the other aren't equal to the values calculated manually
Right now I do not see what I did wrong. Maybe we could wait for others (more experienced) to find the mistake.
Sorry, I tried my best.
Good luck.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by