matlab程序vpa用处,Matlab 提高精度 vpa

MATLAB默认数据类型为double,但在需要更高精度计算时,如计算斜率和倒数,会出现精度不足的问题。vpa函数允许自定义精度进行浮点运算,返回SYM类型的结果。使用vpa时应注意避免先进行双精度计算再转换,以确保精度。例如,计算黄金比例可以使用未求值的字符串或符号表达式,如vpa('(1+sqrt(5))/2')。此外,vpa还可用于显示pi的多位小数。
摘要由CSDN通过智能技术生成

Matlab本身提供了豐富的數據類型(搜索matlab數據類型能找到詳細的介紹),默認的數據類型是double型。

但是偶爾也會出現數據類型精度不夠的情況,比如:計算斜率、倒數時經常出現“差之毫厘謬以千里”的現象。

因此需要提高現有數據類型的精度,matlab提供了可以自定義數據精度的函數vpa——詳見Product Help或help。

需要說明的是:當不再需要高精度時,需要double(數據) -> double類型,或者其他你需要的類型。

>> help vpa

VPA    Variable precision arithmetic.

R = VPA(S) numerically evaluates each element of the double matrix

S using variable precision floating point arithmetic with D decimal

digit accuracy, where D is the current setting of DIGITS.

The resulting R is a SYM.

VPA(S,D) uses D digits, instead of the current setting of DIGITS.

D is an integer or the SYM representation of a number.

It is important to avoid the evaluation of an expression using double

precision floating point arithmetic before it is passed to VPA.

For example,

phi &#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值