zoukankan      html  css  js  c++  java
  • Matlab 提高精度 vpa

    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 = vpa((1+sqrt(5))/2)
        first computes a 16-digit approximation to the golden ratio, then
        converts that approximation to one with d digits, where d is the current
        setting of DIGITS.  To get full precision, use unevaluated string or
        symbolic arguments,
           phi = vpa('(1+sqrt(5))/2')
        or
           s = sym('sqrt(5)')
           phi = vpa((1+s)/2);
     
        Additional examples:
           vpa(pi,780) shows six consecutive 9's near digit 770 in the
              decimal expansion of pi.
     
           vpa(hilb(2),5) returns
     
              [    1., .50000]
              [.50000, .33333]
     
        See also double, digits.

        Overloaded methods:
           sym/vpa

        Reference page in Help browser
           doc vpa

  • 相关阅读:
    Go语言基础练习题系列2
    Go语言基础练习题系列1
    Go语言基础之8--面向对象编程1之结构体(struct)
    Go语言基础之7--函数详解
    分数规划(Bzoj1486: [HNOI2009]最小圈)
    [APIO2018] Circle selection 选圆圈(假题解)
    Bzoj4520: [Cqoi2016]K远点对
    KDTree(Bzoj2648: SJY摆棋子)
    矩阵树定理
    CF235C Cyclical Quest
  • 原文地址:https://www.cnblogs.com/xfzhang/p/2456756.html
Copyright © 2011-2022 走看看