My end value "tc2" comes out as "NaN + NaNi", in the following script and I cant figure out why.
조회 수: 2 (최근 30일)
이전 댓글 표시
%%Pre fault System
clear
clc
Pmax=100;
Pmech=50;
Pe=50;
Delta0=asin(Pe/100);
%%System Under Fault
Pe=0;
r1=0;
Pe=0;
%%System Post Fault
r2=0.8;
DeltaMech=pi-asin(Pmech/r2*Pmax);
%Angle to clear
DeltaC=acos(((DeltaMech-Delta0)*sin(Delta0)-r1*cos(Delta0)+r2*cos(DeltaMech))/(r2-r1));
disp(DeltaC);
%Initial conditions
f=50;
t=0;
derivativeDelta=0;
Delta=0;
c1=0;
c2=Delta0;
%Machine Costant M
H1=10;
H2=10;
H=(H1*H2)/(H1+H2);
M=H/(pi*f);
%Time to clear
tc=sqrt((2*M*(DeltaC-Delta0)/Pmech));
disp(tc);
%%Clearing time with H1=10 and H2= positive infinity;
H2=Inf;
H=(H1*H2)/(H1+H2);
M=H/(pi*f);
%Time to clear
tc2=sqrt((2*M*(DeltaC-Delta0)/Pmech));
disp(tc2);
댓글 수: 0
답변 (1개)
John D'Errico
2024년 11월 2일
편집: John D'Errico
2024년 11월 3일
A NaN means you are doing some operation that has no meaningful result. For example, what is 0/0?
0/0
A mathematician will tell you that we can produce any result you want as some limit from that operatin.Similarly, what is sin(inf)?
sin(inf)
You should see that as you change the argument, sin oscillates from -1 to 1, and so trying to compute sin(inf) is a meaningless thign. So MATLAB returns a NaN.
Similarly, what is inf/inf?
inf/inf
Thse are things that generate a NaN. And to generate a complex NaN, we need do nothing more than
(inf + inf*sqrt(-1))/inf
A quick scan through your code shows things like this:
H2=Inf;
H=(H1*H2)/(H1+H2);
Do you see that will always generate a NaN, since H2 is inf? If you are seeing NaN+Nan*i, that just means that somewhere in that code, you are also generating something complex.
So go through your code, SLOWLY. Look at the result of each line. Does it make sense?
If I look at just the first few lines of your code, I see this:
Pmax=100;
Pmech=50;
Pe=50;
Delta0=asin(Pe/100);
%%System Under Fault
Pe=0;
r1=0;
Pe=0;
%%System Post Fault
r2=0.8;
DeltaMech=pi-asin(Pmech/r2*Pmax)
And there we see some more garbage. asin generates a complex result when you pass it something outside of the interval [-1,1].
Here, Pmech is 50, r2 is 0.8. Pmax is 100.
Do you understand how MATLAB computes a sequence of operations like that?
Pmech/r2*Pmax
MATLAB divides Pmech by 0.8, and then MULTIPLIES the result by Pmax. I think MAYBE you wantd to write
DeltaMech=pi-asin(Pmech/(r2*Pmax))
I might hazard there may be other things you did wrong, given that I found two such obvious mistakes so quickly. Learn to write code more slowly. Look at the result of EVERY LINE, at least until you become good enough that you are not making mistakes like the two I have pointed out.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Detection에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!