Azzera filtri
Azzera filtri

How to set resolution for the numerical calculations in MATLAB

19 visualizzazioni (ultimi 30 giorni)
My objection is to find the roots of a polynomial as precise as possible. Can I use format long (16 digits) to set the resolution? Can this resolution be set higher than this?
  1 Commento
Roger Stafford
Roger Stafford il 23 Gen 2014
Modificato: Azzi Abdelmalek il 24 Gen 2014
As John has indicated, there is a fundamental difference between the precision used in computation and that which is displayed. Using the 'format' command or getting output from 'sprintf' or 'fprintf' affect only the precision displayed and have nothing to do with the precision of computation. The 'double' type number has a fixed computational precision of about 16 significant digits (53 bits), while the 'single' type has a precision of 7 or so significant digits (24 bits). There is no way to alter these. However, matlab has available the Symbolic Toolbox wherein computational precision can be set at whatever number of digits are desired, though of course computation will proceed at a slower pace. Also John has available in the file exchange some functions that allow much greater computational precision. Look at:

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 23 Gen 2014
You would need to use Symbolic Toolbox, or one of John D'Errico's variable-precision packages in the File Exchange.

Più risposte (1)

Azzi Abdelmalek
Azzi Abdelmalek il 23 Gen 2014
sol=roots([1 3 1])
sol1=sprintf('%.20f,',sol)
  6 Commenti
Qingbin
Qingbin il 25 Gen 2014
I am trying to find the roots of two multinomials, say f(T1,T2)=0 and g(T1,T2)=0. f(T1,T2)=0 is calculated from the Routh array of one system and g(T1,T2)=0 is obtained the same way after some further manipulations. The number above is observed as the coefficient of one entry when I was calculating the determinant of the sylvester matrix of the two multninomials eliminating T2.
Sorry for the complexity. But this is what my objective is.
Walter Roberson
Walter Roberson il 25 Gen 2014
Are you using floating point constants at the MATLAB level at any step? For example if you had
syms r
A = pi*r^2 + 2.3
then it would be the floating point approximation of pi that would be used, rather than the irrational number, and it would be the floating point approximation of 2.3 that would be used rather than 23/10.
If you do have any floating point numbers, then to avoid floating point round-off you should convert them to symbolic rationals. Do that by quoting each number and enclosing it with sym(), such as
A = sym('pi') * r^2 + sym('2.3')
Remember to do this for exponents as well, such as x^0.5 should become x^sym('0.5') or better x^sym('1/2') (or clearer still sqrt(x) ) I would need to test to be sure that sym('2.3') did exactly what was desired, but unfortunately I do not have that toolbox.
Once all the floating point numbers (or expressions which could return non-integers) have been sym()'d, then re-run the calculation; there should not be any floating point garbage.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by