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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM