Professional Documents
Culture Documents
2011 1
1.1
Octave ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2
Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3
Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4
( C++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.1
Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2
Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 Octave
3.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.6
3.7
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.8
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
11
4.1
4.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.6
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
liuqiang@coer.zju.edu.cn
15
5.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.2
Multiple graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3
Multiple gures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6 Octave I
18
6.1
Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
20
7.1
if...else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.2
switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
7.3
for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
7.4
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
8 Octave II
23
8.1
1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
8.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
8.3
2:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
26
9.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
9.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
9.3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
9.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
9.5
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
10
31
11 Ax = b
33
12
33
12.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
12.2 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
12.3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
12.4
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
13
35
14
35
14.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
14.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
15 Octave
37
40
40
1
1.1
Octave ?
Octave Matlab Octave
Octave Octave
Octave Octave
1.2
Octave
Octave Octave Mathemat-
icaMaple
()
1.3
Octave
Octave Maltab
1.4 ( C++)
C++ C++
Octave
C++ Octave
2
2.1 Octave
Octave UNIX octave octave
2.2
Octave
Octave Octave
octave:##>2+2
,
ans=4
2.3
Octave 1
C++ Octave
octave:##> exp(1)
ans=2.71813
1.2 sin(40 + ln(2.42 )),
octave:##>1.2*sin(40*pi/180+log(2.4^2))
ans=0.76618
:
1. 1.2 sin
cos
1:
()
sin
()
tan
()
exp
(ex )
log
log10
10
sinh
tanh
cosh
acos
acosh
asin
asinh
atan
atan2
atanh
abs
()
sign
round
oor
ceil
rem
OCTAVE
2. /180 pi Octave
3. logln
Octave
3 Octave
Octave
Octave C++
Octave
3.1
Octave
deg
octave:##> deg=pi/180
deg=0.017453
( C++) Octave Octave
octave:##>1.2*sin(40*deg+log(2.4^2))
ans=0.76618
Octave ans
octave:##> new=3*ans
new=2.2985
new 3 0.76618 Octave
2.2985
Octave a A Octave
OCTAVE
octave:##> who
*** dynamically linked functions:
dispatch
*** currently compiled functions:
rem
*** local user variables:
deg new
clear
:
clear name
name
3.2
Octave format
octave:##> format long
octave 15 octave helpformat
format long deg
octave:##> deg
deg=0.0174532925199433
octave:##> format short
octave
Octave 13142.6 = 1.31426 104 , Octave
1.3143e+04 Octave
Octave
(e.g.3+4i), Octave
(Inf) 0
(NaN) 0 0
Inf NaN Inf NaN
3.3
Octave
12.25
12.25 = 1 101 + 2 100 + 2 101 + 5 102
(1)
1101.01 = 1 23 + 1 22 + 0 21 + 1 20 + 0 21 + 1 22 = 12.25
(2)
OCTAVE
0 1,
(bit)
octave:##> 1-0.2-0.2-0.2-0.2-0.2
ans=5.5511e-17
0.2
(0.2=0.0011001100...) 1/3
Octave()
3.4
Octave Octave
3.5
Octave
()
Octave
OCTAVE
10
3.6
Octave Octave
help commandname
sqrt (X)
If X is negative, a
help -iOctave
Up,Next, Previous
arithmetic
octave:##> help -i arithmetic
q octave
3.7
( bug )
Ctrl-C
11
3.8
Octave
Octave Octave
Octave
4
(array) Octave
(vector)
.
( ) (..)
4.1
[]
octave:##> a=[1 4 5]
a=
1 4 5
octave:##> b=[2,1,0]
b=
2 1 0
octave:##> c=[4;7;10]
c=
4
7
10
octave:##> a=[1 4 5]
a=
1 4 5
octave:##> d=[a 6]
d=
1 4 5 6
4.2
12
octave:##> e=2:6
e=
2 3 4 5 6
octave
a : b : c
octave:##> e=2:0.3:4
e=
2.0000 2.3000 2.6000 2.9000 3.2000 3.5000 3.8000
octave
4.3
Octave
octave:##> v=1:1000
q Octave b
Octave
octave:##> more off
octave:##> more on
4.4
Octave 2
zeros(M,N)
2:
MN
ones(M,N)
MN
linspace(x1,x2,N)
N , x1
x2
logspace(x1,x2,N)
N
10x1 10x2
zeros ones M N
13
4.5
() 1, C C++ 0
octave:##> a=[1:2:6 -1 0]
a=
1 3 5 -1 0
octave:##> a(3)
ans=
5
octave:##> a(3:5)
ans=
5 -1 0
octave:##> a(1:2:5)
ans=
1 5 0
4.6
Octave C++
2, for Octave for
Octave
a
octave:1> a=[1:2:6 -1 0]
a =
1
-1
octave:2> a*2
ans =
2
10
-2
* /
a1
b1
a1 b1
a2 . b2 = a2 b2
a3
b3
a3 b3
(3)
14
.
octave:3> b=1:5
b =
1
octave:4> a.*b
ans =
1
15
-4
octave:5> b.^2
ans =
1
16
25
16
32
octave:6> 2.^b
ans =
2
octave:7> a.^b
ans =
1
125
(element-by-element)
Octave 60 sin
octave:8> angles=[0:pi/3:2*pi]
angles =
0.00000
1.04720
2.09440
3.14159
4.18879
5.23599
6.28319
0.86603
0.00000
-0.86603
-0.86603
-0.00000
octave:9> y=sin(angles)
y =
0.00000
0.86603
15
0.5
-0.5
-1
0
1: y = sin(x) 60
5
Octave GNUPLOT2 3
plot(x,y), x,y
octave:10> plot(angles,y)
1 Octave
y
octave:1> angles=linspace(0,2*pi,100);
octave:2> y=sin(angles);
octave:3> plot(angles,y);
linspace 0 2 100
5.1
Octave plot
octave:4> plot(angles,y,'ro');
3 ( help plot )
title,xlabel ylabel xy
octave:7> title('Graph of y=sin(x)')
octave:8> xlabel('Angle')
octave:9> ylabel('Value')
2
3
www.gnuplot.org
gnuplot
16
xx
-.
++
v
<
>
p
h
replot grid
octave:##> grid on
2
5.2
Multiple graphs
plot x y
octave:##>plot(angles,ycangles,cos(angles));
octave:##>legend('Sine','Cosine');
legend 3 plot
hold plot
octave:13> plot(angles,y,'.')
octave:14> hold on
octave:15> plot(angles,cos(angles),'g-')
octave:16> legend('Sine','Cosine')
hold off
5.3
Multiple gures
figure
octave:##> figure
plot
17
Graph of y=sin(x)
1
Value
0.5
-0.5
-1
0
Angle
2: y = sin(x)
1
Sine
Cosine
0.5
-0.5
-1
0
3: y = sin(x) y = cos(x)
OCTAVE I
18
octave:##> plot(angles,tan(angles))
octave:##> figure(1)
5.4
Octave/Gnuplot Octave print
help print print
octave:##> print('graph1.eps','-deps')
eps
octave:##> print('graph1.png','-dpng')
png
Octave I
Octave
Octave Octave Octave
Octave Octave
Octave
Octave .m (e.g. run.m)
M Octave
Path
6.1
4
/usr/share/octave/3.2.4/m/help
/home/kasion/bin/octavecode
/usr/share/octave/3.2.4/m/plot
/usr/local/share/octave/site-m
/usr/share/octave/3.2.4/m/path
/usr/lib/octave/3.2.4/site/oct/i486-pc-linux-gnu
/usr/share/octave/3.2.4/m/time
/usr/lib/octave/3.2.4/oct/i486-pc-linux-gnu
/usr/share/octave/3.2.4/m/io
/usr/share/octave/3.2.4/m
/usr/share/octave/3.2.4/m/audio
/usr/share/octave/3.2.4/m/deprecated
/usr/share/octave/3.2.4/m/signal
/usr/share/octave/3.2.4/m/set
/usr/share/octave/3.2.4/m/general
OCTAVE I
19
/usr/share/octave/3.2.4/m/linear-algebra
/usr/share/octave/3.2.4/m/elfun
/usr/share/octave/3.2.4/m/testfun
/usr/share/octave/3.2.4/m/specfun
/usr/share/octave/3.2.4/m/miscellaneous
/usr/share/octave/3.2.4/m/pkg
/usr/share/octave/3.2.4/m/special-matrix
/usr/share/octave/3.2.4/m/polynomial
...
octave path addpath
homebob/bin/octave path ,
octave:##> addpath('/home/bob/bin/octave');
savepath path
octave:##> savepath;
path doc path help path
6.2
(,emacs, vi, notepad) Octave
octave:##> edit
emacs5 edit
run.m edit run
Octave
%Script to calculate and plot a rectified sine wave
t=linspace(0,10,100);
y=abs(sin(t)); % The abs command makes all negative numbers positive
plot(t,y);
title('Rectified Sine Wave');
xlabel('t');
% Octave
rectsin.m
Octave rectsin
octave:##> rectsin
octave
6.3
Octave
what :
5
edit Octave
20
Rectified Sine Wave
1
0.8
0.6
0.4
0.2
0
0
10
4: rectsin
octave:##> what
M-files in directory /home/kasion/tmp:
rectsin.m
...
Octave rectsin
>> help rectsin
Script to calculate and plot a rectified sine wave
Octave help
Octave Octave
7.1
if...else
if Octave if
if expression
statements
elseif
expression
statements
21
4:
==
if x==y
if x =y
>
if x>y
>=
if x>=y
<
if x<y
<=
if x<=y
&
if x==1 | y>2
x~= y
else
statements
end
C++ Octave () (
), statments { } Octave end if
Octave ,if...end if...endif . end Octave Matlab
.
if Octave
octave:##> a=0;b=2;
octave:##> if a>b
c=3
else
c=4
end
c=4
if Octave end
Octave
1 0
octave:##> 1==2
ans=
0
octave:##> pi>exp(1) & sqrt(-1)==i
ans=
1
4 C++
22
switch
7.2
if/elseif switch
switch x
case x1
statements
case x2
statements
otherwise
statements
end
switch x case statements
Octave switch C++ break Octave
statements swith otherwise
octave:##> a=1;
octave:##> switch a
case 0
disp('a is zero');
case 1
disp('a is one');
otherwise
disp('a is not a binary digit');
end
a is one
disp
e.g. disp(a) a
for
7.3
for Octave
for for for
for variable=vector
statements
end
vector ( 4.2 )
octave:##> for n=1:5
nf(n)=factorial(n);
end
OCTAVE II
23
octave:##> disp(nf)
1 2 5 24 120
for octave nf(n)
while
7.4
Octave while
while expression
statements
end
octave:##> x=1;
octave:##> while 1+x>1
x=x/2;
end
octave:##>x
x=
1.1102e-16
Octave II
Octave
function [output1,output2,...]=name(input1,input2,...)
M M sind()
sind.m M
Octave
8.1 1:
Octave
sin(d/180*pi) d
sind(d)(sine in degrees) sind.m
OCTAVE II
24
function s=sind(x)
% SIND(x) Calculates sine(x) in degrees
s=sin(x*pi/180);
endfunction
2. Line2 Octave
help sind Octave
3. Line3 x s
4. Line4 Octave endfunction Octave return (
)
8.2
sind.m M .m
path (), Octave
sind
octave:##> help sind
SIND(x) Calculates sine(x) in degrees
octave:##> sin(0)
ans=
0
octave:##> sin(45)
ans=
0.7071
octave:##> t=sin([30 60 90])
t=
0.5000 0.8660 1.0000
x
sin
OCTAVE II
25
8.3 2:
0 t < t
0
y=
1 otherwise
: t0
function y=ustep(t,t0)
%USTEP(t,t0) unit step at t0
% A unit step is defined as
%
0 for t<t0
1 for t>=t0
[m,n]=size(t);
%Check that this is a vector, not a matrix i.e. (1 x n) or (m x 1)
if m~=1 & n ~=1
error('T must be a vector');
end
y=zeros(m,n); %Initialise output array
for k=1:length(t)
if t(k)>=t0
y(k)=1; % Otherwise, leave it at zero, which is correct
endif
endfor
endfunction
1. Line1 ustep t t0
y
2. Line2-5
3. Line6 ustep t
size Octave
4. Line7-10
error
5. Line11 t
6. Line12 t y for
length t
26
Example of function Ustep
2
1.5
0.5
-0.5
-1
-1
5:
7. Line13-15 t < t0 y
t >= t0 y = 1
(m,n k )
y
ustep.m
octave:##> t=-1:0.1:4;
octave:##> v=ustep(t,0)-ustep(t,1);
octave:##> plot(t,v);
octave:##> axis([-1 4 -1 2]);
5
m n m n 2 3
[
]
5 7 9
1 3 2
Octave
octave:##> A=[5 7 9
-1 3 -2]
A=
27
-1
-2
-1
octave:##> C=[1:3;8:-2:4]
C=
1
>D=[1 2 3];
>D=[D; 4 5 6]
>D=[D; 7 8 9]
>D=
1
9.1
*
> A*B
ans=
19
-7
-4
-3
> B*C
ans=
2
-8
-6
-4
> A*C
error operator *: nonconformant arguments (op1 is 2x3, op2 is 2x3)
,
(l m) (m n) (l n)
(4)
28
octave:2> A^2
ans =
5
A2 = A A.*
:
octave:1> A=[1 2;2 1]
A =
1
octave:3> A.*B
ans =
1
octave:4> A.^2
ans =
1
octave:5> 2.^A
ans =
2
29
9.2
A AT octave
octave:6> A=[5 7 9;-1 3 -2]
A =
5
-1
-2
octave:7> A'
ans =
5
-1
-2
9.3
Octave ones zeros 1
0
t I Octave eye
octave:8> I=eye(4)
I =
Diagonal Matrix
1
octave:9> I*[5;8;2;0]
ans =
5
8
2
0
Octave diag
:
30
diag
octave:11> diag(A)
ans =
5
3
octave:12> E=[]
E = [](0x0)
9.4
Octave
octave:22> B=[2 0;0 -1;1 0]
B =
2
-1
-1
-1
-2
10
31
9.5
()
octave:24> J=[1 2 3 4
> 5 6 7 8
> 11 12 13 10]
J =
1
11
12
13
10
octave:25> J(1,1)
ans =
octave:26> J(2,3)
ans =
12
13
10
octave:29> J(3,2:3)=[-1 0]
J =
1
11
-1
10
10
Octave ( 5 ) size
( AA1 = A1 A = I)
10
32
eye
5:
zeros
ones
rand
diag
inv
det
trace
eig
rank
null
rref
lu
qr
svd
pinv
tt inv
octave:3> A=[3 0 4;0 1 -2;2 1 3]
A =
3
-2
octave:4> inv(A)
ans =
0.71429
0.57143
-0.57143
-0.57143
0.14286
0.85714
-0.28571
-0.42857
0.42857
octave:5> A*inv(A)
ans =
1.00000
0.00000
0.00000
0.00000
1.00000
0.00000
-0.00000
0.00000
1.00000
11 AX = B
33
Octave det
octave:6> det(A)
ans =
11
Ax = b
12
Octave GNUPLOT
3D Octave
GNUPLOT
12.1
tt subplot
subplot(row,columns,select)
subplot
subplot
octave:25> x=linspace(-10,10);
octave:26> subplot(2,1,1)
octave:27> plot(x,sin(x));
octave:28> subplot(2,1,2)
octave:29> plot(x,sin(x)./x)
6 sinc
12.2
3D
Octave 3D 3D
tt plot3 x,y
tt z
octave:11> z = [0:0.05:5];
octave:12> plot3 (cos(2*pi*z), sin(2*pi*z), z, ";helix;")
7 3D xlabel ylabel zlabel z
3D 3
12.3
3D
6 Octave view ( help view
)
12
34
0.5
-0.5
-1
-10
-5
10
-5
10
0.8
0.6
0.4
0.2
-0.2
-0.4
-10
6: subplot
helix
01
0.5
0.5
0
0
-0.5
-0.5
-1 -1
7: plot3
LMB+motion
<Ctrl>+LMB+motion
(Rotate axes6 )
6:
13
35
surf
mesh
0.5
0.5
-0.5
-0.5
-112
-112
10
8
6
4
2
0 0
10
10
12
8
6
4
2
0 0
10
12
contour
meshz
12
10
0.5
0
-0.5
4
-112
10
8
6
4
2
0 0
10
12
0
0
10
12
8: 3D
3D f (x, y)
Octave meshgird
octave:17> x=2:0.2:4;
octave:18> y=1:0.2:3;
octave:19> [X,Y]=meshgrid(x,y);% make the grid
12.4
X,Y
f (x, y) = (x 3)2 (y 2)2
Octave
octave:20> Z=(X-3).^2-(Y-2).^2;
octave:21> subplot(2,2,1);surf(Z);title('surf')
octave:22> subplot(2,2,2);mesh(Z);title('mesh')
octave:23> subplot(2,2,3);meshz(Z);title('meshz')
octave:24> subplot(2,2,4);contour(Z);title('contour')
8
13
14
Octave Octave
14
36
(z = a + bi)
imag
real
abs
r = |z|
conj
z 0 = a bi
angle
= sin( ab )
7:
octave:40> z1=4-3i
z1 =
4 - 3i
tt i
tt j Octave ( 1)
octave:41> z2=1+3j
z2 =
1 + 3i
octave:42> z2-z1
ans = -3 + 6i
octave:43> z1+z2
ans =
octave:44> z2/z1
ans = -0.20000 + 0.60000i
octave:45> z1^2
ans =
7 - 24i
Octave
7 Octave sin(x) ex
14.1
Octave
tt plot Argand ( x y )
octave:3> plot(z1,'*',z2,'*')
octave:4> axis([-5 5 -5 5])
9
14.2
Octave roots
tt root
x5 + 2x4 5x3 + x + 3 = 0
15 OCTAVE
37
-2
-4
-4
-2
9:
tt roots
octave:12> roots([1 2 -5 0 1 3])
ans =
-3.44726 + 0.00000i
1.17303 + 0.39021i
1.17303 - 0.39021i
-0.44940 + 0.60621i
-0.44940 - 0.60621i
15 Octave
Unix , Octave .
,
. Octave ,
.
, hello :
#!octave-interpreter-name -qf
# a sample Octave program
printf ("Hello, world!\n");
15 OCTAVE
38
hello
. #! ,
. #! Octave . Octave
, -qf ,-q
, f ~/.octaverc 7 .
Octave , . Octave
argv . :
#! /bin/octave -qf
printf ("%s\n", program_name ());
arg_list = argv ();
for i = 1:nargin
printf (" %s\n", arg_list{i});
endfor
printf ("\n");
test , :
kasion@tmp:$ chmod u+x test
kasion@tmp:$ ./test arg1 arg2 arg3
:
kasion@tmp:$ ./test arg1 arg2 arg3
test
arg1
arg2
arg3
test PATH (/usr/bin /home/kasion/bin ),
ls,cd test , shell script , .
, .
1.3000000000e+00 2.9549292750e+00 2.9349509600e+00
1.3102040816e+00 2.9454196710e+00 2.9248815610e+00
1.3204081633e+00 2.9359134520e+00 2.9148026660e+00
1.3306122449e+00 2.9264083650e+00 2.9047117190e+00
...
7
15 OCTAVE
39
, TE TM .
D=
d2 nef f
C d2
Getdistetm :
!/usr/bin/octave -q
# no comments...
#print the messages
clear all;
printf("Programe name :%s\n", program_name ());
printf("Processing ....\n");
format long;
#basic constants
C=3e2; # light speed in freespace [um/ps]
#load the data
arglist=argv ();
...
#load the data
buffer=load(arglist{1});
lam=buffer(:,1);
neffte=buffer(:,2);
nefftm=buffer(:,3);
#caculate the dipersion
fitorder=4;
Pte=polyfit(lam,neffte,fitorder);
Ptm=polyfit(lam,nefftm,fitorder);
for k=1:(fitorder-1)
P2te(k)=(fitorder+1-k)*(fitorder-k)*Pte(k);
P2tm(k)=(fitorder+1-k)*(fitorder-k)*Ptm(k);
end
d2neffte=polyval(P2te,lam);
....
outdata=[lam Dispersionte Dispersiontm];
#save the result
save("-ascii",outfile,"outdata");
#plot and save the figure;
figure;
plot(lam,Dispersionte,'k:','LineWidth',2,lam,Dispersiontm,'r-','LineWidth',2);
...
grid on;
(5)
40
print(figurename,'-dpng','-S680,500');
printf("Done!\n");
# End of the script
:
Octave :http://www.gnu.org/software/octave/docs.html
Octave :http://ljk.imag.fr/membres/Christophe.Prudhomme/courses/octave/octave-refcard-a4.pdf
Octave :http://octave.1599824.n4.nabble.com/
This document has been produced as a tutoial to acompany the version of Octave supplied
CMI-www.cambridge-mint.org
MDP-http://www-mdp.eng.cam.ac.uk
41
Signicaant reference has been made to the resources generated and maintianed by John Eaton
and his team at www.octave.org. As indicated above, the tutorial is heavily based on Paul Smiths
Original in which he acknowledges advice and help from Roberto Cipolla, Richard Prager, Hugh
Hunt, Maurice Ringer, David Mansergh and Martin Szummer.
42
2011 , :
Matlab Octave
, , <Octave >
,Octave ,
, LATEX , kile
error ,
, ,
:
:liuqiang@coer.zju.edu.cn
,