Info
This question is closed. Reopen it to edit or answer.
use of If else condition
1 view (last 30 days)
Show older comments
Hi all, I am trying to plot a function in which If else condition is required.
I wrote a following code, May any body correct it...
code:
clear all
clc
format longEng
syms z1 z2 z
phi=(pi/180)*39;
delta=(pi/180)*26;
gma=18.4;
h=4;
h1=1.91;
h2=0.08;
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);
if Rp1<1
k=kp11;
else
k=kp12;
end
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);
if Rp2<1
k=kp21;
else
k=kp22;
end
pa1=ka1;
pp1=k;
pp2=k;
pa2=-ka2;
fplot(pa1,[0 h+h1])
hold on
fplot(pp1,[h h+h1])
hold on
fplot(pp2,[h+h1 L])
hold on
fplot(pa2,[h+h1 L])
hold off
grid on
1 Comment
Geoff Hayes
on 23 Feb 2019
Akshay - are Rp1 and Rp2 symbolic expressions? Do you need to convert it to a double (numeric value) before trying to compare either with 1?
Answers (1)
Naman Bhaia
on 26 Feb 2019
Hey Akshay,
I have looked at the question and I believe it is similar to a previously answered question, I hope this link helps.
3 Comments
Naman Bhaia
on 26 Feb 2019
So I havent looked at what the code is trying to do but to resolve the issue, define the value for 'z' somewhere and then do one of the following for comparing the values:
- if eval(subs(Rp1))>1, or
- if double(subs(Rp1))>1
Try and see which option suits you.
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!