Octave
- clear
- クリア
- source
- ソースを読み込ませ実行
- whos
- 登録されている関数を調べる
- clg
- 描画したグラフを消す?
- hold on
- グラフの重ね書きモードオン
Shape from shading
function xdot=f(x,t)
> xdot=zeros(5,1);
> xdot(1)=-x(3) .* ( x(3).^2 + x(4).^2 + 1 ).^(-3./2);
> xdot(2)=-x(4) .* ( x(3).^2 + x(4).^2 + 1).^(-3./2);
> xdot(3)=-2 * x(1);
> xdot(4)=-2 * x(2);
> xdot(5) = x(3).*(-x(3) .* ( x(3).^2 + x(4).^2 + 1 ).^(-3./2)) + x(4).* (-x(4) .* ( x(3).^2 + x(4).^2 +1).^(-3./2));
> endfunction
ローレンツアトラクタ
x(0)=z(0)=0, y(0)=1
dx/dt = -10(x(t)-y(t))
dy/dt = -x(t)z(t)+28x(t)-y(t)
dz/dt = x(t)y(t)-8z(t)/3
function xdot = f (x, t)
xdot = zeros (3,1);
xdot(1) = -10 * (x(1)-x(2));
xdot(2) = - x(1)*x(3) + 28*x(1)-x(2);
xdot(3) = x(1)*x(2)-8*x(3)/3;
endfunction
x0=[0;1;0]
t = linspace(0, 20, 3000);
y = lsode("f", x0, t);
plot(y(:,1), y(:,2))
三次元で描画させるには
gset parametric
gsplot([y(:,1) y(:,2) y(:,3)])
常微分方程式の解
x'' + 4*x' + 13*x = 0, x'(0) = 1, x(0) = 1
の解を求める.一階の常微分方程式に書き改めると次のようになる.
x1' = x2
x2' = -4*x2 - 13*x1
octave: > function xdot = f(x, t)
xdot(1) = x(2);
xdot(2) = -4*x(2) - 13*x(1);
endfunction
octave: > x0 = [1; 1]
octave: > t = linspace(0, 4, 1000);
octave: > y = lsode("f", x0, t);
octave: > plot(t, y)
octave: > grid "on"
octave: > plot(t, y(:, 1))
octave: > hold on
octave: > plot(t, y(:, 2))
octave: > hold off
octave: > plot(y(:, 1), y(:, 2))
octave: > closeplot
関連リンク
- http://www.al.cs.kobe-u.ac.jp/~inamoto/octave.html
-