다음 연립 미분방정식과 초기조건 x(0) = 1, y(0) = 2 를 만족하는 두 함수  x = x(t), y = y(t)  의 그래프를 그려보자.

dx/dt = r*x*(1 -x/k) -a*x*y/(1 + b*x)
dy/dt = c*a*x*y/(1 + b*x) - d*y

단, 여기서 r = 0.25
               k = 1.4
               a = 1.5
               b = 0.16
               c = 0.9

이다.

즉,

dx/dt = 0.25*x*(1 -x/1.4) - 1.5*x*y/(1 + 0.16*x)
dy/dt = 3*1.5*x*y/(1 + 0.16*x) - 0.8*y

 

[Octave 소스파일: f.m]--------------------------------
function xdot = f (x, t)

  r = 0.25;
  k = 1.4;
  a = 1.5;
  b = 0.16;
  c = 0.9;
  d = 0.8;

  xdot(1) = r*x(1)*(1 - x(1)/k) - a*x(1)*x(2)/(1 + b*x(1));
  xdot(2) = c*a*x(1)*x(2)/(1 + b*x(1)) - d*x(2);
endfunction

graphics_toolkit gnuplot
x0 = [1; 2];
t = linspace (0, 50, 200)';
x = lsode ("f", x0, t);
plot (t, x)

--------------------------------------------------------------
 

 

Posted by Scripter
,

plot 명령을 내리기 전에 graphics_toolkit gnuplot 명령을 먼저 내린다.

 

명령 프롬프트> octave -qi
octave:1> graphics_toolkit gnuplot
octave:2> x = linspace(0,1,400);
octave:3> y = x.^2;
octave:4> plot(x,y)

  

* 위의 코드로 그래프 창이 나타나지 않을 경우 다음 코드를 시도한다.

명령 프롬프트> octave -qi
octave:1> graphics_toolkit gnuplot
octave:2> setenv('GNUTERM','wx');
octave:3>x = linspace(0,1,400);
octave:4>y = x.^2;
octave:5> plot(x,y)

 

 

 

Cygwin 의 X 터미널에서 Octave 를 실행할 경우:

$ startx

또는

$ xinit

한 후 Octave 를 실행시켜서,

plot 명령을 내리기 전에 setenv("GNUTERM", "X11") 명령을 먼저 내린다.

 

쉘 프롬프트$ octave -qi
octave:1> x = linspace(0,1,400);
octave:2> y = x.^2;
octave:3> setenv("GNUTERM", "X11");
octave:4> plot(x,y);

 

 

이번에는 세 함수

    y = cos 2x,   y = sin 4x,  y = 2sin x

의 그래프를 한 좌표평면에 그려보자.

$ xinit

한 후, X 터미널에서

$ octave -qi
octave:1> x = linspace(0, 2*pi);
octave:2> a = cos(2*x);
octave:3> b = sin(4*x);
octave:4> c = 2*sin(x);
octave:5> setenv("GNUTERM", "X11");
octave:6> figure;
octave:7> hold off;
octave:8> plot(x, a, x, b, x, c);
octave:9> close all

 

 

Posted by Scripter
,