0

I have a problem accessing the element of a vector in octave:

>> den = [1 2 1 2]
>> poles = roots(den)
>> poles =

  -2.00000 + 0.00000i
   0.00000 + 1.00000i
   0.00000 - 1.00000i
>> poles(2)
ans = 4.1633e-016 + 1.0000e+000i

Instead of returning 0 + 1i, it returns 4.1633e-016 + 1.0000e + 000i. Why?

how can I solve that?

Geronimo
  • 461
  • 5
  • 23
  • Please read this FAQ entry http://wiki.octave.org/FAQ#Why_is_this_floating_point_computation_wrong.3F – Andy Jun 09 '17 at 06:50

1 Answers1

1

What you see in the first result is correct. The precision of presentation is up to 5 digit precision. In the second call to see the result is presented in scientific format, so you can see the real value of the what you see in a limited format of the presentation.

I should have mentioned that sometimes you get a very small value, which means zero, but because of some error in computation you've gotten a very small value instead of zero. You can use format long E before your code to get the results in a detail scientific format.

OmG
  • 18,337
  • 10
  • 57
  • 90
  • ok I understand. how can I solve that? – Geronimo Jun 08 '17 at 03:01
  • There is not any problem which you want to solve that! It's a precision of the presentation. You can use `format long E` to receive what you want. – OmG Jun 08 '17 at 03:17