Use of nested loop
2 views (last 30 days)
Show older comments
I wrote a program using nested loop. It shows error "The following error occurred converting from sym to double:
DOUBLE cannot convert the input expression into a double array."
code:
clear all
clc
format longEng
syms z
phi=(pi/180)*39;
delta=(pi/180)*26;
gma=18.4;
h=4;
h1=1.9185831159674030330446155463409;
h2=0.088292704979722319631609763226466;
L=h+h1+h2;
beta=1;
alfa=1;
z1=z-h;
z2=z-h-h1;
Ra1=-1;
Ra2=-(alfa*(z2/h2))^0.5;
Rp1=3*(beta*(1-(z1/(h1))))^0.5;
Rp2=3*(alfa*(z2/h2))^0.5;
delma1=0.5*(1-Ra1)*delta;
delma2=-0.5*(1-Ra2)*delta;
delmp1=0.5*(Rp1-1)*delta;
delmp2=0.5*(Rp2-1)*delta;
ka1=(2*cos(phi)^2)/(cos(phi)^2*(1+Ra1)+cos(delma1)*(1-Ra1)*(1+sqrt((sin(phi+delma1)*sin(phi))/cos(delma1)))^2);
ka2=(2*cos(phi)^2)/(cos(phi)^2*(1+Ra2)+cos(delma2)*(1-Ra2)*(1+sqrt((sin(phi+delma2)*sin(phi))/cos(delma2)))^2);
kp11=(2*cos(phi)^2)/(cos(phi)^2*(1+Rp1)+cos(delmp1)*(1-Rp1)*(1+sqrt((sin(phi+delmp1)*sin(phi))/cos(delmp1)))^2);
kp12=1+0.5*(Rp1-1)*((cos(phi)^2/(cos(delmp1)*(-sqrt((sin(phi+delmp1)*sin(phi))/cos(delmp1))+1)^2))-1);
kp21=(2*cos(phi)^2)/(cos(phi)^2*(1+Rp2)+cos(delmp2)*(1-Rp2)*(1+sqrt((sin(phi+delmp2)*sin(phi))/cos(delmp2)))^2);
kp22=1+0.5*(Rp2-1)*((cos(phi)^2/(cos(delmp2)*(-sqrt((sin(phi+delmp2)*sin(phi))/cos(delmp2))+1)^2))-1);
i=0;
for z=0:0.02:L
i=i+1;
if(z<h)
k1(i)=ka1;
k2(i)=0;
elseif(z>=h && z<(h+h1))
k1(i)=ka1;
for Rp1=0:0.02:3
if Rp1<1
k2(i)=kp11;
else
k2(i)=kp12;
end
end
else
for Rp2=0:0.02:3
if Rp1<1
k1(i)=kp21;
else
k1(i)=kp22;
end
end
k2(i)=ka2;
end
end
z=0:0.02:L;
subplot(2,1,1);
plot(z,k1,z,k2)
grid on
0 Comments
Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!