gpt4 book ai didi

matlab - 有没有办法在 MATLAB 中增加 'realmax'?

转载 作者:太空宇宙 更新时间:2023-11-03 20:20:51 24 4
gpt4 key购买 nike

我机器上的realmax是:

1.7977e+308

我知道我必须以一种避免长整数计算的方式编写我的代码,但是有什么办法可以增加限制吗?
我的意思是像 C 中的 gmp 库

最佳答案

您可能会发现 vpa (可变精度算术)有帮助:

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.

这是一个如何使用它的例子:

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

注意:

  • 输出 x符号 ( sym ) 类型。当然,你不应该把它转换成double,因为它会超过realmax:

    >> double(x)
    ans =
    Inf
  • 使用字符串输入 以避免将大输入值计算为double。例如,这不起作用

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

    因为10^500被计算为double,给出infthen作为输入到 vpa

关于matlab - 有没有办法在 MATLAB 中增加 'realmax'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30383286/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com