필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

use of If else condition

조회 수: 2 (최근 30일)
Akshay Pratap Singh
Akshay Pratap Singh 2019년 2월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Geoff Hayes
Geoff Hayes 2019년 2월 23일
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?

답변 (1개)

Naman Bhaia
Naman Bhaia 2019년 2월 26일
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
Naman Bhaia
Naman Bhaia 2019년 2월 26일
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:
  1. if eval(subs(Rp1))>1, or
  2. if double(subs(Rp1))>1
Try and see which option suits you.
Akshay Pratap Singh
Akshay Pratap Singh 2019년 2월 26일
I tried. It is giving wrong answers. You please check.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by