프로그래밍/Octave
Octave 로 구하는 이차방정식의 근
Scripter
2014. 1. 27. 19:05
프롬프트> octave -qi
octave:1> # Let's find roots of the equation x^2 - 5 = 0.
octave:1> c = [1, 0, -5]; # 다항식의 계수들
octave:2> roots(c)
ans =
-2.2361
2.2361
octave:3> x = roots(c);
octave:4> x(1)
ans = -2.2361
octave:5> x(2)
ans = 2.2361
octave:6> sqrt(5)
ans = 2.2361
octave:7> format long
octave:8> x
x =
-2.23606797749979
2.23606797749979
octave:9> x(1), x(2)
ans = -2.23606797749979
ans = 2.23606797749979
octave:10> sqrt(5)
ans = 2.23606797749979