ERROR-The statement cannot be reached
이전 댓글 표시
theta = linspace(0,360,361);
theta_rad = theta*pi/180;
is_crossply = 0;
animate = 1;
an_speed = .001;
l=[-30 4*2*.0052 1;
60 4*2*.0052 1];
E = [19.4000001e6 1.4e6 .30 .702e6 -.5e-6 15e-6;
5.84e6 .9e6 .2 .3e6 0.0e-6 0.0e-6];
T1_theta = @(ang) [(cos(ang))^2 (sin(ang))^2 2*sin(ang)*cos(ang);
(sin(ang))^2 (cos(ang))^2 -2*sin(ang)*cos(ang);
-sin(ang)*cos(ang) sin(ang)*cos(ang) (cos(ang))^2-(sin(ang))^2 ];
if is_crossply
M = cosd(2*theta);
else
n = size(l,1);
h = zeros(n+1,1);
A = zeros(3);
B = zeros(3);
D = zeros(3);
D_0 = zeros(3);
D_90 = zeros(3);
D_top = zeros(3);
D_bot = zeros(3);
M = zeros(3,3,length(theta));
R = [ 1 0 0 ;
0 1 0 ;
0 0 2 ];
total = sum(l,1);
thick = total(1,2);
h(1) = -thick/2;
imax = n + 1;
for i = 2 : imax
h(i) = h(i-1) + l(i-1,2);
end
for j = 1:length(theta)
for i = 1:n
mi=l(i,3);
v21 = E(mi,2)*E(mi,3)/E(mi,1);
d = 1 - E(mi,3)*v21;
Q = [E(mi,1)/d v21*E(mi,1)/d 0;
E(mi,3)*E(mi,2)/d E(mi,2)/d 0;
0 0 E(mi,4)];
a1=l(i,1)*pi/180;
T1 = [(cos(a1))^2 (sin(a1))^2 2*sin(a1)*cos(a1);
(sin(a1))^2 (cos(a1))^2 -2*sin(a1)*cos(a1);
-sin(a1)*cos(a1) sin(a1)*cos(a1) (cos(a1))^2-(sin(a1))^2 ];
Qxy = inv(T1)*Q*R*T1*inv(R);
A = A + Qxy*(h(i+1)-h(i));
B = B + Qxy*(h(i+1)^2 - h(i)^2);
D = D + Qxy*(h(i+1)^3 - h(i)^3);
if i <= n/2
disp('comp D_top')
T1_top = T1_theta(-a1+theta_rad(j));
Q_top = inv(T1_top)*Q*R*T1_top*inv(R);
D_top = D_top + Q_top*(h(i+1)^3 - h(i)^3);
T1_90 = T1_theta(pi/2);
Q_90 = inv(T1_90)*Q*R*T1_90*inv(R);
D_90 = D_90 + Q_90*(h(i+1)^3 - h(i)^3);
T1_0 = T1_theta(0);
Q_0 = inv(T1_0)*Q*R*T1_0*inv(R);
D_0 = D_0 + Q_0*(h(i+1)^3 - h(i)^3);
elseif i > n/2
disp('comp D_bot')
T1_bot = T1_theta(-a1+theta_rad(j));
Q_bot = inv(T1_bot)*Q*R*T1_bot*inv(R);
D_bot = D_bot + Q_bot*(h(i+1)^3 - h(i)^3);
else
disp('ERROR h(i)=0')
end
end
format short e
A = 1.0*A;
B = .5*B;
D = (1/3)*D;
D_top = (1/3)*D_top;
D_bot = (1/3)*D_bot;
D_0 = (1/3)*D_0;
D_90 = (1/3)*D_90;
M(:,:,j) = (D_bot-D_top)./(D_0-D_90);
end
end
if is_crossply
posMi = find(M>=0);
negMi = find(M<=0);
posM = polar(theta_rad(posMi),M(posMi));
hold on;
negM = polar(theta_rad(negMi),M(negMi));
set(posM , ...'Color','r',...'LineWidth',2)
set(negM , ...'Color','b',...'LineWidth',2,...'LineStyle','--')
title('Bending Stiffness Mismatch, M')
hold off;
if animate
for i = 1:2:length(M)
subplot(1,2,1)
t = 0 : .01 : 2 * pi;
P = polar(t, 1 * ones(size(t)));
hold on;
anim = polar(theta_rad(i),M(i));
hold on;
[X,Y] = pol2cart(theta_rad(i),M(i));
str = [' \leftarrow ',num2str(M(i))];
Mtext = text(X,Y,str);
posM = polar(theta_rad(posMi),M(posMi));
hold on;
negM = polar(theta_rad(negMi),M(negMi));
hold on;
set(P, 'Visible', 'off')
set(anim,...'Marker','o',...'MarkerSize',10)
set(Mtext,...'FontSize',16)
set(posM , ...'Color','r',...'LineWidth',2)
set(negM , ...'Color','b',...'LineWidth',2,...'LineStyle','--')
title('Bending Stiffness Mismatch, M')
hold off;
subplot(1,2,2)
xdir = [1;0];
ydir = [0;1];
R = [ cos(theta_rad(i)) -sin(theta_rad(i)) ;
sin(theta_rad(i)) cos(theta_rad(i))];
xp = R*xdir;
yp = R*ydir;
xpaxis = plot([0 xp(1)],[0 xp(2)]);
hold on;
ypaxis = plot([0 yp(1)],[0 yp(2)]);
hold on;
xfixed = plot([0 1],[0 0]);
hold on;
yfixed = plot([0 0],[0 1]);
hold on;
xpaxis_text = text(xp(1),xp(2),' x''');
ypaxis_text = text(yp(1),yp(2),' y''');
xfixed_text = text(1,0,' x');
yfixed_text = text(0,1,' y');
angle_text = text(1,1,['\theta = ',num2str(theta(i))]);
set(xpaxis,...'LineWidth',2,...'Color','green')
set(ypaxis,...'LineWidth',2,...'Color','magenta')
set(xfixed,...'LineWidth',2,...'Color','black')
set(yfixed,...'LineWidth',2,...'Color','black')
axis([-1.5 1.5 -1.5 1.5])
axis square
axis off
title('Current Coordinate System')
hold off;
pause(an_speed)
end
end
end
if is_crossply ~= 1
Mrs = reshape(M(1,1,:),[1,length(theta)]);
t = 0 : .01 : 2 * pi;
P = polar(t, 1 * ones(size(t)));
hold on;
posMi = find(Mrs>=0);
negMi = find(Mrs<=0);
posM = polar(theta_rad(posMi),Mrs(posMi));
hold on;
negM = polar(theta_rad(negMi),Mrs(negMi));
hold on;
set(P, 'Visible', 'off')
set(posM , ...'Color','r',...'LineWidth',2)
set(negM , ...'Color','b',...'LineWidth',2,...'LineStyle','--')
title('Bending Stiffness Mismatch, M') \
hold off;
end
line 14 and 85 shows that the statement cannot be reached. Kindly help.
댓글 수: 2
Alex Sune
2019년 5월 9일
I guess it is just a warning, because they are inside an if 0:
if is_crossply %This variable is 0
%Some code that cannot be reached
end
@Pritam Ghosh: your code is very badly aligned. Badly aligned code is one way that beginners hide bugs in their code. You should align your code consistently, e.g. using the default setting of the MATLAB editor.
Note that your code has many syntax warnings which you should pay attention to. Do NOT ignore them!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!