Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to increase 'realmax' in MATLAB?

Tags:

matlab

realmax on my machine is:

1.7977e+308

I know I have to write my code in a way to avoid long integer calculations, but is there any way to increase the limit?
I mean something like gmp library in C

like image 915
Zeta.Investigator Avatar asked Feb 01 '26 23:02

Zeta.Investigator


1 Answers

You may find vpa (variable- precision arithmetic) helpful:

R = vpa(A) uses variable-precision arithmetic (VPA) to compute each element of A to at least d decimal digits of accuracy, where d is the current setting of digits.

R = vpa(A,d) uses at least d significant (nonzero) digits, instead of the current setting of digits.

Here's an example how to use it:

>> x = vpa('10^500/20')
ans =
5.0e498

Note that:

  • The output x is of symbolic (sym) type. Of course, you shouldn't convert it to double, because it would exceed realmax:

    >> double(x)
    ans =
       Inf
    
  • Use string input in order to avoid evaluating large input values as double. For example, this doesn't work

    >> vpa(10^500/20)
    ans =
    Inf
    

    because 10^500 is evaluated as double, giving inf, and then is used as an input to vpa.

like image 80
Luis Mendo Avatar answered Feb 03 '26 19:02

Luis Mendo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!