Running through a loop and storing values
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I am trying to run through some Matlab code but I cant seem to find the solution that I need, I know that its simple but I just cant remember. I have some formulae running through a loop, eachn time the angle is changing within the formulae. However i want to store the value of each loop in a matrix each time so that I can use it later in the programme, but the MatLab programme is just storing the very last calculated value of the loop if you understand what I mean. Below is the code:
%MatLab Programme by Stephen Trainor %21/01/12
% PROGRAMME INPUTS%
%lay-up properties%
fibre_angle = [0 30 -30 90 90 -30 30 0];
thickness = [0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125];
material = [1 1 1 1 1 1 1 1]; %material properties%
El(1)=76*10^9; %pascals
Et(1)=5.5*10^9; %pascals
Glt(1)=2.3*10^9;%pascals
vlt(1)=0.34;
%Loading; input the predetermine stress OR strain
Sigma=[0;0;0];% Applied stress matrix
Eps=[0;0;0];% Applied strain matrix
%CTE matrix
Alpha = [1.2*10^-6;24.2*10^-6;0];
%Temperature change
dT=-40;
%Qstar Inputs%
x=4; %the fraction relating the number of times the angle is reoccurring
a=2; %fraction of first angle
b=0; %fraction of second angle
c=0; %fraction of third angle
d=1; %fraction if angle is 0
e=1; %fractin if angle is 90
%no more programme inputs
%%%%------------------------------------------------------------%%%
%MAIN PROGRAMME%
%%%%------------------------------------------------------------%%%
%calculating all parts of Q matrix
Q11 = El/(1-((vlt^2)*Et/El))
Q22 = Et/(1-((vlt^2)*Et/El))
Q12 = (vlt*Et)/(1-((vlt^2)*Et/El))
Q66 = Glt
Q=[Q11,Q12,0; Q12,Q22,0; 0,0,Q66];
%angles to radians%
fibre_radians=(3.14/180)*fibre_angle;
num=size(fibre_angle); %used in transformation loop
num=num(2);
%creating equivalent laminate
A=zeros(3,3);
total_thickness=sum(thickness);
Nt=0;
NT=[0;0;0];
l=0;
for i=1,num; %rotation of ply and assembly loop%
m=cos(fibre_radians(i));
n=sin(fibre_radians(i));
Q11bar = (Q11*m^4)+(Q22*n^4)+2*(m^2)*(n^2)*(Q12+2*Q66)
Q12bar = ((Q11+Q12-4*Q66)*(m^2)*(n^2))+Q12*((m^4)+(n^4))
Q16bar = ((Q11-Q12-2*Q66)*(m^2)-(Q22-Q12-2*Q66)*(n^2))*m*n
Q22bar = Q22*(m^4)+Q11*(n^4)+2*(Q12+2*Q66)*(m^2)*(n^2)
Q26bar = -((Q22-Q12-2*Q66)*(m^2)-(Q11-Q12-2*Q66)*(n^2))*m*n
Q66bar = (Q11+Q22-2*(Q12+Q66))*(m^2)*(n^2)+Q66*((m^4)+(n^4))
Qbar(i)=[Q11bar,Q12bar,Q16bar; Q12bar,Q22bar,Q26bar; Q16bar,Q26bar,Q66bar];
What I am looking to fid is Q11bar, Q22bar, Q12bar, Q66 bar for each loop and its corresponding angle.
Please help if you have any ideas?
Stephen
0 个评论
回答(2 个)
Sravantej
2012-2-7
hi stephen, you might be getting onlt the last values of Q11bar, Q22bar....this is because you are using just Q11bar instead of Q11bar(i). If you use Q11bar(i), at the end of the loop Q11bar will be a vector instead of a single value. So, try with Q11bar(i)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!