Why do I get NAN?
Show older comments
Hey everyone,
I'm running this equation
hMphi(1) = - (dd_Anis(1) * ddu_acos(1) * du_dMphi(1))/(C2*sin(Mtheta(1)))- ((Is*P_hbar/(2*P_Q*g*C2))*((ephix(1)*Ffx(1))+(ephiy(1)*Ffy(1))))- Ms*(Ny-Nx)*sin(Mtheta(1))*sin(2*Mphi(1))+ (Happy*cos(Mphi(1)) - Happx*sin(Mphi(1))) ;
in a loop and a certain point the value of this vector becomes a NAN?! Can Anyone tell me why is this happening? I' dividing by a sin, so I thought that maybe the problem is from it, but I printed the values of it I didn't get Inf.
Thanks
Accepted Answer
More Answers (2)
Jan
on 19 Jan 2014
You can stop the code automatically, when the NaN appears:
dbstop if naninf
Then inspect the local variables and evaluate the different parts of the equation in the command window until you find the reason for the NaN.
1 Comment
Dheeraja Karthikeyan
on 25 Apr 2020
Thanks a lot for this! You were a blessing in disguise!
Anna
on 19 Jan 2014
1 vote
Have you tried to isolate the part of the equation where the fault is at? Debug the equation in the loop iteration before the equation turns into a NaN.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!