0

I've got one problem for a longer time and I'd be really grateful if you could help me somehow...

I have a code in MATLAB (version R2012a) where I compute some exponential functions using MATLAB's fuction exp. This means that I have something like this:

y = exp(x);

However, when this "x" is larger than a certain number, the result ("y") is infinity; when "x" is smaller than a certain number, the result is 0. As said on the MathWorks' website:

Numerical exceptions may happen, when the absolute value of the real part of a floating-point argument x is large. If ℜ(x) < -7.4*10^8, then exp(x) may return the truncated result 0.0 (protection against underflow). If ℜ(x) > 7.4*10^8, then exp(x) may return the floating-point equivalent RD_INF of infinity.

My problem is quite obvious - my "x" are pretty large so I receive infinities and zeros instead of results I need. My question is - how do I get the real results? Thanks in advance for help!

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
hejnevim
  • 1
  • 1

2 Answers2

2

Use vpa with a string input:

>> exp(1000)
ans =
   Inf

>> vpa('exp(1000)')
ans =
1.9700711140170469938888793522433*10^434

Note the result of vpa is of class sym.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
0

A variable in any language is stored in a certain amount of bytes in the computer's memory. The more bytes used to hold a variable type, the more precise of a result that variable can hold. If you are using integers, the biggest type uses 64 bytes and is uint64. This is an unsigned integer (meaning it can only be positive) that can range from 0 to 18,446,744,073,709, 551,615. If you need decimals, try using vpa.

David
  • 757
  • 1
  • 7
  • 17