My end value "tc2" comes out as "NaN + NaNi", in the following script and I cant figure out why.

3 visualizaciones (últimos 30 días)
%%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);

Respuestas (1)

John D'Errico
John D'Errico el 2 de Nov. de 2024
Editada: John D'Errico el 3 de Nov. de 2024 a las 15:13
A NaN means you are doing some operation that has no meaningful result. For example, what is 0/0?
0/0
ans = NaN
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)
ans = NaN
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
ans = NaN
Thse are things that generate a NaN. And to generate a complex NaN, we need do nothing more than
(inf + inf*sqrt(-1))/inf
ans = NaN + NaNi
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)
DeltaMech = 1.5708 + 9.4335i
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
ans = 6250
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))
DeltaMech = 2.4665
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.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by