My end value "tc2" comes out as "NaN + NaNi", in the following script and I cant figure out why.
24 次查看(过去 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,17:47
编辑:John D'Errico
2024-11-3,15:13
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!