2014/01/27 3

Octave 로 구하는 이차방정식의 근

프롬프트> 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.23606797..

Octave 로 계산 하는 집합 연산 몇 가지

프롬프트> octave -qi octave:1> a = [1, 2, 3]; octave:2> b = [5, 3, 4, 3]; octave:3> union(a, b) # 합집합 ans = 1 2 3 4 5 octave:4> intersect(a, b) # 공통집합 ans = 3 octave:5> setdiff(a, b) # 차집합 ans = 1 2 octave:6> setdiff(b, a) # 차집합 ans = 4 5 octave:7> setxor(a, b) # 대칭차(symmetric difference) ans = 1 2 4 5 octave:8> unique(b) # 중복 허용 않는 집합 ans = 3 4 5 octave:9> ismember(a, b) # 원소 확인 ans = 0 0 1 octave:..

Cygwin 의 Octave 로 그린 평면 매개곡선을 jpg 파일로 저장하기

Cygwin 의 터미널에서 $ xinit 하여 X 터미널을 열고, X 터미널의 쉘 프롬프트에서 $ octave -qi 하여 Octave 를 시작하여 다음 Octave 명령들을 입력한다. (saveas() 명령으로 그림을 파일로 저장할 수 있다.) octave:1> t = linspace(0, 2*pi, 500); octave:2> x = cos(t).**3; octave:3> y = sin(t).**3; octave:4> plot(x, y); # => error! octave:5> setenv("GNUTERM", "X11"); # 윈도우즈에서는 graphics_toolkit gnuplot; octave:6> plot(x, y); octave:7> saveas(1, "figure_asterisk.jpg",..