next up previous contents
Next: 関数 Up: Octave メモ Previous: データ解析

常微分方程式系

常微分方程式系

\begin{displaymath}\frac{d\bm{x}}{dt}=\bm{f}(\bm{x},t), \quad \bm{x}, \bm{f} \in \mathbb{R} ^n
\end{displaymath}

を解くには,

例
octave:1> function xdot = f(x,t)
> k = 1.0;
> xdot(1) = x(2);
> xdot(2) = -k * x(1);
> endfunction
octave:2> x0 = [0; 1];
octave:4> t = linspace(0,4,10)'
t =

  0.00000
  0.44444
  0.88889
  1.33333
  1.77778
  2.22222
  2.66667
  3.11111
  3.55556
  4.00000

octave:5> x = lsode("f", x0, t);
octave:6> plot (t,x)
octave:7> plot (t,x(:,1))
ooctave:8> gplot x
octave:11> tx=[t x(:,1)];
octave:12> gplot tx

なお, function の戻り値は xdot 以外でもよい.



Toru Sasaki
2001-07-23