2014-08-27 81 views

回答

5

与64位浮点运算作业较小,100^1000inf,因为它比最大可能值。如果符号数学工具箱,则用vpasym有大量的工作:

sym('100^1000') 

vpa('100^1000') 
5

正如丹尼尔已经指出的那样,这是太大,通过以下甚至输出的数量MATLAB本身。对于不同的数据类型,该数字是用realmax获得的。作为表示/使用如此巨大数字的替代方案,您可以使用相应的mantissaexponent而不是base-10 representation,这是通常的MATLAB表示形式。这里列出了获取这两个函数的功能 -

function [mantissa, base10_exponent] = base10_mantissa_exponent(base,exponent) 

act_exp = exponent*log10(abs(base)); 
base10_exponent = floor(act_exp); 
mantissa = power(10,act_exp - base10_exponent); 

if rem(exponent,2)==1 && sign(base)==-1 
    mantissa = -mantissa; 
end 

return; 

下面列出几个运行示例并与用于验证的实际MATLAB运行进行比较。

例#1

base = -125.343; 
exponent = 101; 
usual_approach = base^exponent 
[mantissa, base10_exponent] = base10_mantissa_exponent(base,exponent) 

输出 -

usual_approach = 
-8.0930e+211 
mantissa = 
    -8.0930 
base10_exponent = 
    211 

实施例#2(在所讨论的问题的问题)

base = 100; 
exponent = 1000; 

输出 -

usual_approach = 
    Inf 
mantissa = 
    1 
base10_exponent = 
     2000 
1

要处理大量也有类High Precision Float,与该结果可以通过写

a = hpf(100); 
b = hpf(1000); 
c = a^b; 

这给c = 1.e2000来实现。拨打struct(c)可以提供有关如何在内部存储号码的信息。

struct(c) 

ans = 

NumberOfDigits: [64 4] 
    DecimalBase: 4 
      Base: 10000 
     Numeric: 0 
      Sign: 1 
     Exponent: 2001 
     Migits: [1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 
相关问题