Octave 科學計算 -- 簡介

# 範例一

``````octave-3.2.4.exe:1> a=[1 2; 3 4]
a =

1   2
3   4

octave-3.2.4.exe:2> b = [2 3; 4 5]
b =

2   3
4   5

octave-3.2.4.exe:3> c=a+b
c =

3   5
7   9

octave-3.2.4.exe:4> (8+3)*5
ans =  55
octave-3.2.4.exe:5> 10*sin(pi/3)*sin(pi/3)
ans =  7.5000
octave-3.2.4.exe:6> b=rand(3,2);
octave-3.2.4.exe:7> b
b =

0.805572   0.757786
0.932863   0.614612
0.074403   0.916952

octave-3.2.4.exe:8> a=[1,1,2; 3,5,8; 13, 21, 34]
a =

1    1    2
3    5    8
13   21   34

octave-3.2.4.exe:9> 2*a
ans =

2    2    4
6   10   16
26   42   68

octave-3.2.4.exe:10> a*b
ans =

1.8872    3.2063
7.6763   12.6820
32.5923   53.9345

octave-3.2.4.exe:11> a'*a
ans =

179    289    468
289    467    756
468    756   1224

octave-3.2.4.exe:12> a\b
warning: matrix singular to machine precision, rcond = 1.47189e-018
warning: attempting to find minimum norm solution
warning: dgelsd: rank deficient 3x3 matrix, rank = 2
ans =

1.23765   1.31327
-1.05177  -1.10326
0.18588   0.21002```
```

# 範例二

``````octave-3.2.4.exe:13> 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
octave-3.2.4.exe:14> x0 = [1;2];
octave-3.2.4.exe:15> t=linspace(0,50,200)';
octave-3.2.4.exe:16> x=lsode("f", x0, t);
octave-3.2.4.exe:17> plot(t,x)```
```