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

后端 未结 1 1024
渐次进展
渐次进展 2021-01-20 04:59

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

相关标签:
1条回答
  • 2021-01-20 05:31

    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.

    0 讨论(0)
提交回复
热议问题