MATLAB中的双精度型 [英] Double type in MATLAB

查看:595
本文介绍了MATLAB中的双精度型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于MATLAB的精度,我有两个问题

I have two questions regarding precision in MATLAB

1)对于浮点复数,数字位数最大的数据类型是否为double?

1) Is double the data type with the most large number of digits for a float complex number?

2)如何提高integrate()的精度?在我看来,E + 15左右有一个上限(很多)

2) How can the precision of integral() be augmented? It seems to me that there is a cap at around E+15 (for a large number)

推荐答案

下面是一个示例脚本,将doublesymbolic/vpa精度进行了比较:

Here's an example script comparing double to symbolic/vpa precision:

% Numeric approach
f_numeric = @(z) exp(z.^2);
Out_numeric = integral (f_numeric, 0, 1);

% Symbolic / vpa approach
syms x
f_symbolic(x) = exp(x^2);
Out_symbolic = int (f_symbolic, x, [0,1]);

% Comparison
fprintf('Numeric  : %0.30f\n', Out_numeric)
fprintf('Symbolic : %s\n'    , char   (vpa (Out_symbolic, 32)))
fprintf('Converted: %0.30f\n', double (vpa (Out_symbolic, 32))) % back to double

我的机器上的输出(eps = 2.2204e-16):

Output on my machine (eps = 2.2204e-16):

Numeric  : 1.462651745907181499717353290180
Symbolic : 1.462651745907181608804048586857
Converted: 1.462651745907181499717353290180

更一般地:

>> fprintf(' %0.32f\n %s\n', 1/3, char (vpa ('1/3', 32)))
 0.33333333333333331482961625624739
 0.33333333333333333333333333333333

这篇关于MATLAB中的双精度型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆