Reputation: 633
When the eigenvalues of matrices with integer entries (even 3x3 matrices) are calculated in Octave, sometimes it reports a floating point value like 9.1940e-17, whereas it should really be zero. For example, when I am plotting some numbers modulo 1, a value -2e-17 is becoming 1 in the plot, but it should actually be 0.
Although I can approximate the answers upto some decimal places later, it will still internally calculate upto 17 decimal places while calculating the eigenvalue and waste calculation time. Is it possible to work with only upto something like 8 decimal places for all quantities from the beginning?
If that is not possible, is it possible to tell octave (once and for all in a script) to approximate all quantities upto 8 decimal places while reporting?
Upvotes: 1
Views: 412
Reputation: 36710
What you are asking for won't help, it makes it worse. Setting the precision to 8 decimal points (or significant digits) won't make numerical errors disappear, it will increase the numerical errors to that magnitude. Take a simple calculation:
x=1/3
y=x*6
Now you would end up with 1.99999998
, a much larger error.
There are libraries doing the opposite, increasing the precision. In Octave that's called vpa.
Upvotes: 2
Reputation: 60615
To complement Daniel's answer, the additional precision doesn't cost any additional time. The computer works with the number as a whole, not with individual digits.
You might want to use
A(abs(A)<1e-8) = 0;
after computing your final result A
to set the near-zero values to zero.
Upvotes: 3