Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
use of If else condition
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Geoff Hayes
el 23 de Feb. de 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?
Respuestas (1)
Naman Bhaia
el 26 de Feb. de 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 comentarios
Naman Bhaia
el 26 de Feb. de 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.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!