MATLAB precision

后端 未结 3 1910
遥遥无期
遥遥无期 2020-12-11 01:23

How can I implement quadruple precision (128 bit arithmetic) in MATLAB while solving a Matrix eigenvalue problem ?

I am trying to solve a linear stability analysis p

3条回答
  •  不思量自难忘°
    2020-12-11 02:16

    I do have a general precision floating point arithmetic toolbox in MATLAB, that does not require the symbolic toolbox. It is available on the File Exchange now. As an example, in 200 digits of precision...

    >> X = hpf('1.2',200)
    X =
        1.2
    
    >> X^723 - 2
    ans =
        1770275636625441478440184064843963160282702377364043536065.674784028
    335311702907341138106304578079399191891193908698215227428501441099262538
    4031886249461115861966367898404170725299823585166135087107488           
    

    If you wish to do all of your arithmetic in 200 digits of precision when HPF numbers are employed, then just specify that as the default.

    >> DefaultNumberOfDigits 200
    >> hpf('pi')
    ans =
        3.141592653589793238462643383279502884197169399375105820974944592307
    816406286208998628034825342117067982148086513282306647093844609550582231
    7253594081284811174502841027019385211055596446229489549303819           
    

    HPF is not a true variable precision tool by design since it works in a fixed number of digits. It is reasonably efficient up to a few tens of thousands of digits. So to get 100 digits of exp(pi), this takes about 1/4 of a second.

    >> timeit(@() exp(hpf('pi',100)))
    ans =
       0.2643
    

    Trig functions too. Here 1000 digits of the sin(pi). It should be zero of course.

    >> tic,sin(hpf('pi',1000)),toc
    ans =
        0
    Elapsed time is 0.201679 seconds.
    

提交回复
热议问题