While loop not giving the correct answer
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi All,
the code below is running, HOWEVER the results are incorrect,
My condition in while is running but with wrong numbers, anyone help ??
My while condition is to get the factor results greater than 1 and smaller or equal to 1.5 HOWEVER, the results are factor =
1.0e+03 *
0.0105 2.4436
Please anyone help !!!
clearvars;
close all;
clc;
syms s real;
rr=0;
factor=[0 0]
while all(factor)>1||all(factor)<=1.5
factor=[0 0]
angle_pss=[0 45 -45 30 90;45 -45 45 90 30];
thick_pss=[.125 .15 .25 .5 1;.125 .15 .25 .5 1];
rr=rr+1
% STEP ONE
E1=1.4e3;E2=1.4e3;G12=.53e3;v12=.35;
if rr>length(angle_pss)
return
end
angle=angle_pss(:,rr)';
thickness=thick_pss(:,rr)';
% STEP TWO
S=q_cal(angle,E1,E2,G12,v12);
% STEP THREE
sigma1_c=1500; sigma2_c=246; sigma1_t=1500; sigma2_t=40; tau_12=68;
H1=(1/sigma1_t) - (1/sigma1_c); H11= 1/(sigma1_t*sigma1_c); H2=(1/sigma2_t) - (1/sigma2_c); H22=1/(sigma2_t*sigma2_c); H6=0; H66=1/(tau_12)^2;
H12=-1/2*sqrt(1/(sigma1_t*sigma1_c*sigma2_t*sigma2_c));
% STEP FOUR
[T_zinv,T_z_,Q_tran]=q_tran_cal(angle,S);
% STEP FIVE
Z=h_mid(angle,thickness);
% STEP SIX
[A,B,D]=abd_cal(angle,Z,Q_tran);
% STEP SEVEN
M=[A B;B D];
F=[0;0;0;0;0;10]; % ADD APPLIED FORCES HERE
%F=[N_x;N_y;N_xy;M_x;M_y;M_xy;]
E=M\F; % STRAIN % inv(M)*F
e=E(1:3);
k=E(4:end); % curvature
% STEP EIGHT
[sigmal_t,sigmal_m,sigmal_b]=stress_strain_cal(angle,e,Z,k,Q_tran,thickness,T_zinv,T_z_);
% STEPNINE
tsai_wu=zeros(2,1,length(angle));
for i=1:length(angle)
tsai_wu(:,:,i)=double(solve((H1*sigmal_t(1,:,i)+H2*sigmal_t(2,:,i)+H6*sigmal_t(3,:,i))*s...
+(H11*sigmal_t(1,:,i)^2+H22*sigmal_t(2,:,i)^2+H66*(sigmal_t(3,:,i)^2)+2*H12*sigmal_t(1,:,i)*sigmal_t(2,:,i))*s^2==1,s))
tsai_w=tsai_wu(find(tsai_wu(:,:,i)>0),:,i)
factor(i)=tsai_w
end
thickness
angle
end
댓글 수: 0
답변 (1개)
Ameer Hamza
2020년 9월 10일
The correct condition for while-loop is
while ~(all(factor>1) && all(factor<=1.5))
apart from that, there seems to be some other issue with the program logic, which never creates 'factor' fulfilling this condition.
댓글 수: 5
Ameer Hamza
2020년 9월 10일
Yes, I meant that the condition
~(all(factor>1) && all(factor<=1.5))
never become true. What do you expect to happen when this condition never becomes true?
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!