Why do I get the message NaN?

2 visualizzazioni (ultimi 30 giorni)
Max
Max il 30 Gen 2016
Risposto: Walter Roberson il 3 Feb 2016
Hello,
I would like to calculate the expression below. But I always get: NaN. I can´t find my mistake.
Can somebody help me?
I4=5.718534314;
I5=-0.001546715453;
Cov__B_C_direct =1125899906842624*exp(I4^(4831891999187463/1125899906842624))*exp(8187485477687969/1715238139330560)*((230090095199403*...
exp(-I4^(4831891999187463/1125899906842624))*exp(-8187485477687969/1715238139330560)*I4^...
(3705992092344839/1125899906842624))/1233348233694652400 - (2558136220007576158378628793351*...
exp(-I4^(4831891999187463/1125899906842624))*exp(-8187485477687969/1715238139330560)*I5*I4^(2580092185502215/1125899906842624))/10681743549394799937933824491520 + ...
(3335311470258831134378888053767*exp(-I4^(4831891999187463/1125899906842624))*exp(-8187485477687969/1715238139330560)*...
I5* I4^(3705992092344839/562949953421312))/10681743549394799937933824491520)
  1 Commento
Star Strider
Star Strider il 30 Gen 2016
When I converted it into a symbolic by putting:
syms I4 I5
between the assignments to those and your equation, I got:
Error using mupadengine/feval (line 163)
Exponent overflow.
I suspect you’re dividing Inf/Inf, which will evaluate to NaN.
This is an observation, not an Answer, so I’m not posting it as one.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 3 Feb 2016
When I test in a different software package, I find no problem with the representation, even if I convert the floating point numbers to rationals. I do not find any portion of the expression to be particularly large.
An algebraic equivalent to the expression is
(16191151046901145333338734592/77084264605915775) * I4^(3705992092344839/1125899906842624) - (2558136220007576158378628793351/9487294105343480) * I5 * I4^(2580092185502215/1125899906842624) + (3335311470258831134378888053767/9487294105343480) * I5 * I4^(3705992092344839/562949953421312)
Caution: remember that all of those fractions are going to be evaluated to floating point numbers, losing precision in the process. If you do not want that, then you need to use the Symbolic Toolkit, with code such as
Cov__B_C_direct = sym('1125899906842624') * exp(I4^(sym('4831891999187463') / sym('1125899906842624'))) * exp(sym('8187485477687969') / sym('1715238139330560')) * ((sym('230090095199403') * exp(-I4^(sym('4831891999187463') / sym('1125899906842624'))) * exp(-sym('8187485477687969') / sym('1715238139330560')) * I4^(sym('3705992092344839') / sym('1125899906842624'))) / sym('1233348233694652400') - (sym('2558136220007576158378628793351') * exp(-I4^(sym('4831891999187463') / sym('1125899906842624'))) * exp(-sym('8187485477687969') / sym('1715238139330560')) * I5 * I4^(sym('2580092185502215') / sym('1125899906842624'))) / sym('10681743549394799937933824491520') + (sym('3335311470258831134378888053767') * exp(-I4^(sym('4831891999187463') / sym('1125899906842624'))) * exp(-sym('8187485477687969') / sym('1715238139330560')) * I5 * I4^(sym('3705992092344839') / sym('562949953421312'))) / sym('10681743549394799937933824491520'))
Or in the reduced form,
Cov__B_C_direct = (sym('16191151046901145333338734592') / sym('77084264605915775')) * I4^(sym('3705992092344839') / sym('1125899906842624')) - (sym('2558136220007576158378628793351') / sym('9487294105343480')) * I5 * I4^(sym('2580092185502215') / sym('1125899906842624')) + (sym('3335311470258831134378888053767') / sym('9487294105343480')) * I5 * I4^(sym('3705992092344839') / sym('562949953421312'))

Più risposte (1)

Abhisek Roy
Abhisek Roy il 3 Feb 2016
Hi Max,
It looks like some part of the expression reaches the maximum representable value for a double precision floating point number (which you can find using the function 'realmax'), it overflows, so it is represented as 'inf'. At this point, the numerical result no longer correctly represents the value of the function.
As a workaround for this type of issue try to re-express the function in a different form which does not contain quantities that overflow. In this case, simplify it if possible.

Community Treasure Hunt

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

Start Hunting!

Translated by