-
Octave
2011 1
1 41.1 Octave ? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.3 Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.4 ( C++) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 42.1 Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Octave 73.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 114.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1
-
2
5 155.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155.2 Multiple graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165.3 Multiple figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6 Octave I 186.1 Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
7 207.1 if...else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207.2 switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.3 for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.4 while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
8 Octave II 238.1 1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248.3 2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
9 269.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
10 31
11 Ax = b 33
12 3312.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3312.2 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3312.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3312.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
13 35
14 3514.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3614.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
-
3
15 Octave 37
A 40
B 40
-
1 4
1
1.1 Octave ?
Octave Matlab Octave
Octave Octave Octave Octave
Octave Octave J.W.Eation GNU General Public Licence Octave Matlab
1.2 Octave
Octave Octave Mathemat-icaMaple ()
1.3 Octave
Octave Maltab NASA ; Jaguar Racing F1 ;Sheffield Octave
1.4 ( C++)
C++ C++ Octave C++ Octave
2
2.1 Octave
Octave UNIX octave octave
GNU Octave, version 3.2.4Copyright (C) 2009 John W. Eaton and others.This is free software; see the source code for copying conditions.There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE. For details, type `warranty'.
-
2 5
Octave was configured for "i486-pc-linux-gnu".
Additional information about Octave is available at http://www.octave.org.
Please contribute if you find this software useful.For more information, visit http://www.octave.org/help-wanted.html
Report bugs to (but first, please readhttp://www.octave.org/bugs.html to learn how to write a helpful report).
For information about changes from previous versions, type `news'.Octave:1>
Octave Octave:>1 Octave Octave quit exit
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
-
2 6
1: cos ()sin ()tan ()exp (ex)log e log10 10 sinh tanh cosh acos acosh asin asinh atan atan2 1
atanh abs ()sign round floor ceil fix 0 rem
-
3 OCTAVE 7
2. /180 pi Octave
3. logln
Octave
3 Octave
Octave Octave C++
Octave
3.1
Octave deg
octave:##> deg=pi/180deg=0.017453
( C++) Octave Octave
octave:##>1.2*sin(40*deg+log(2.4^2))ans=0.76618
Octave ans
octave:##> new=3*ansnew=2.2985
new 3 0.76618 Octave 2.2985
Octave a A Octave pii j(i = j =
1()) Octave
sin cos
-
3 OCTAVE 8
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:##> degdeg=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)
-
3 OCTAVE 9
0 1, (bit)
octave:##> 1-0.2-0.2-0.2-0.2-0.2ans=5.5511e-17
0.2 (0.2=0.0011001100...) 1/3 Octave()
3.4
Octave Octave
octave:##> save anyname
anyname.mat (.mat octave ) Octave Octave
octave:##> load anyname
octave:##>save filename var1 var2 ...
deg
octave:##> save degconv deg
deg degconv.mat
octave:##> load degconv
Octave
3.5
Octave ()
Octave
-
3 OCTAVE 10
3.6
Octave Octave
help commandname
octave:1> help sqrt`sqrt' is a built-in function
-- Mapping Function: sqrt (X)Compute the square root of each element of X. If X is negative, acomplex result is returned. To compute the matrix square root, see*note Linear Algebra::.
See also: realsqrt
Additional help for built-in functions and operators isavailable in the on-line version of the manual. Use the command`doc ' to search the manual index.
Help and information about Octave is also available on the WWWat http://www.octave.org and via the [email protected] list.
help -iOctave Up,Next, Previous
arithmetic
octave:##> help -i arithmetic
q octave
3.7
( bug )
Ctrl-C
-
4 11
3.8
Octave Octave Octave Octave
4
(array) Octave (vector)
( ) (...)
4.1
[]
octave:##> a=[1 4 5]a=
1 4 5octave:##> b=[2,1,0]
b=2 1 0
octave:##> c=[4;7;10]c=
4710
;
octave:##> a=[1 4 5]a=
1 4 5octave:##> d=[a 6]
d=1 4 5 6
4.2
-
4 12
octave:##> e=2:6e=
2 3 4 5 6
octave a : b : c
octave:##> e=2:0.3:4e=
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
2: zeros(M,N) MN ones(M,N) MN linspace(x1,x2,N) N , x1
x2logspace(x1,x2,N) N
10x1 10x2
zeros ones M N
-
4 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 0octave:##> 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 3 5 -1 0
octave:2> a*2ans =
2 6 10 -2 0
+
* / a1a2a3
. b1b2b3
=a1b1a2b2a3b3
(3)
-
5 14
.
octave:3> b=1:5b =
1 2 3 4 5
octave:4> a.*bans =
1 6 15 -4 0
octave:5> b.^2ans =
1 4 9 16 25
octave:6> 2.^bans =
2 4 8 16 32octave:7> a.^b
ans =
1 9 125 1 0
(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
octave:9> y=sin(angles)y =
0.00000 0.86603 0.86603 0.00000 -0.86603 -0.86603 -0.00000
-
5 15
-1
-0.5
0
0.5
1
0 1 2 3 4 5 6 7
1: y = sin(x) 60
5
Octave GNUPLOT23plot(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')
2www.gnuplot.org3 gnuplot
-
5 16
3: plot ( help plot),( Matlab )w . - m o : c x x -. r + + g * b s y d k 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 onoctave:15> plot(angles,cos(angles),'g-')octave:16> legend('Sine','Cosine')
hold off
5.3 Multiple figures
figure
octave:##> figure
plot
-
5 17
-1
-0.5
0
0.5
1
0 1 2 3 4 5 6
Val
ue
Angle
Graph of y=sin(x)
2: y = sin(x)
-1
-0.5
0
0.5
1
0 1 2 3 4 5 6 7
SineCosine
3: y = sin(x) y = cos(x)
-
6 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
6 Octave I
Octave Octave Octave Octave Octave Octave Octave
Octave .m (e.g. run.m) M Octave
6.1 Path 4 Octave path Octave
Octave path Octave path ( linux /usr/share/octave) (pwd) path
octave:##> path. /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
4
-
6 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 :
5edit Octave
-
7 20
0
0.2
0.4
0.6
0.8
1
0 2 4 6 8 10
t
Rectified Sine Wave
4: rectsin
octave:##> whatM-files in directory /home/kasion/tmp:rectsin.m...
Octave rectsin
>> help rectsinScript to calculate and plot a rectified sine wave
Octave help
7
Octave Octave
7.1 if...else
if Octave if
if expressionstatements
elseif expressionstatements
-
7 21
4:
== if x==y= if x =y> if x>y>= if x>=y< if x a=0;b=2;octave:##> if a>b
c=3else
c=4endc=4
if Octave end Octave
1 0
octave:##> 1==2ans=
0octave:##> pi>exp(1) & sqrt(-1)==i
ans=1
4 C++
-
7 22
7.2 switch
if/elseif switch
switch xcase x1statements
case x2statementsotherwisestatements
end
switch x case statements Octave switch C++ break Octave statements swith otherwise
octave:##> a=1;octave:##> switch a
case 0disp('a is zero');
case 1disp('a is one');
otherwisedisp('a is not a binary digit');
enda is one
disp e.g. disp(a) a
7.3 for
for Octave for for for
for variable=vectorstatements
end
vector ( 4.2 )
octave:##> for n=1:5nf(n)=factorial(n);
end
-
8 OCTAVE II 23
octave:##> disp(nf)1 2 5 24 120
for octave nf(n)
7.4 while
Octave while
while expressionstatements
end
octave:##> x=1;octave:##> while 1+x>1
x=x/2;end
octave:##>xx=
1.1102e-16
8 Octave II
Octave
Octave reference 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
-
8 OCTAVE II 24
function s=sind(x)% SIND(x) Calculates sine(x) in degreess=sin(x*pi/180);endfunction
1. Line1 Octave sind
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 sindSIND(x) Calculates sine(x) in degrees
octave:##> sin(0)ans=
0octave:##> sin(45)
ans=0.7071
octave:##> t=sin([30 60 90])t=
0.5000 0.8660 1.0000
x sin
-
8 OCTAVE II 25
8.3 2:
y =
0 t < t01 otherwise: t0
function y=ustep(t,t0)%USTEP(t,t0) unit step at t0% A unit step is defined as% 0 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');endy=zeros(m,n); %Initialise output arrayfor k=1:length(t)if t(k)>=t0
y(k)=1; % Otherwise, leave it at zero, which is correctendifendforendfunction
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
-
9 26
-1
-0.5
0
0.5
1
1.5
2
-1 0 1 2 3 4
y
t
Example of function Ustep
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
9
m n m n 2 3 [5 7 9
1 3 2
]
Octave
octave:##> A=[5 7 9-1 3 -2]
A=
-
9 27
5 7 9-1 3 -2
octave:##> B=[2 0; 0 -1;1 0]octave:##> B=
2 00 -11 0
octave:##> C=[1:3;8:-2:4]C=
1 2 38 6 4
>D=[1 2 3];>D=[D; 4 5 6]>D=[D; 7 8 9]>D=
1 2 44 5 67 8 9
9.1
*
> A*Bans=19 -7-4 -3
> B*Cans=2 4 6-8 -6 -41 2 3
> A*Cerror operator *: nonconformant arguments (op1 is 2x3, op2 is 2x3)
,
(l m) (m n) (l n) (4)
-
9 28
octave:1> A=[1 2;2 1]A =
1 22 1
octave:2> A^2ans =
5 44 5
A2 = A A.* :
octave:1> A=[1 2;2 1]A =
1 22 1
octave:2> B=[1 2;3 4]B =
1 23 4
octave:3> A.*Bans =
1 46 4
octave:4> A.^2ans =
1 44 1
octave:5> 2.^Aans =
2 44 2
-
9 29
9.2
A AT octave
octave:6> A=[5 7 9;-1 3 -2]A =
5 7 9-1 3 -2
octave:7> A'ans =
5 -17 39 -2
9.3
Octave ones zeros 1 0 t I Octave eye
octave:8> I=eye(4)I =
Diagonal Matrix
1 0 0 00 1 0 00 0 1 00 0 0 1
octave:9> I*[5;8;2;0]ans =
5820
Octave diag :
-
9 30
octave:10> diag([-1 7 2])ans =
Diagonal Matrix
-1 0 00 7 00 0 2
diag
octave:11> diag(A)ans =
53
octave:12> E=[]E = [](0x0)
9.4
Octave
octave:22> B=[2 0;0 -1;1 0]B =
2 00 -11 0
octave:23> comp=[eye(3) B;A zeros(2,2)]comp =
1 0 0 2 00 1 0 0 -10 0 1 1 05 7 9 0 0-1 3 -2 0 0
-
10 31
9.5
()
octave:24> J=[1 2 3 4> 5 6 7 8> 11 12 13 10]J =
1 2 3 45 6 7 811 12 13 10
octave:25> J(1,1)ans = 1octave:26> J(2,3)ans = 7octave:27> J(1:2,4)% rows 1-2, column 4ans =
48
octave:28> J(3,:) % row 3, all columnsans =
11 12 13 10
octave:29> J(3,2:3)=[-1 0]J =
1 2 3 45 6 7 811 -1 0 10
10
Octave ( 5 ) size ( AA1 = A1A = I)
-
10 32
5: eye zeros ones rand diag inv det trace eig rank null Calculate a basis for the null space of a matrixrref Perform Gaussian elimination on an augmented matrixlu Calculate the LU decomposition of a matrixqr Calculaate the QR decompotitionof a matrixsvd Calculate the SVD of a matrixpinv Calculate the pseudoinverse of a matrix
tt inv
octave:3> A=[3 0 4;0 1 -2;2 1 3]A =
3 0 40 1 -22 1 3
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.000000.00000 1.00000 0.00000-0.00000 0.00000 1.00000
-
11 AX = B 33
Octave det
octave:6> det(A)ans = 7
11 Ax = b
12
Octave GNUPLOT3D 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.4
-0.2
0
0.2
0.4
0.6
0.8
1
-10 -5 0 5 10
-1
-0.5
0
0.5
1
-10 -5 0 5 10
6: subplot
helix
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
10
1
2
3
4
5
7: plot3
LMB+motion +LMB+motion (Rotate axes6)
6:
-
13 35
0
2
4
6
8
10
12
0 2 4 6 8 10 12
contourmeshz
02
46
810
12
02
46
810
12-1
-0.5
0
0.5
1
mesh
02
46
810
12
02
46
810
12-1
-0.5
0
0.5
1
02
46
810
12
02
46
810
12-1
-0.5
0
0.5
1
surf
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 areal babs r = |z|conj z = a biangle = sin(a
b)
7:
octave:40> z1=4-3iz1 = 4 - 3i
tt i tt j Octave (
1)
octave:41> z2=1+3jz2 = 1 + 3i
octave:42> z2-z1ans = -3 + 6ioctave:43> z1+z2ans = 5octave:44> z2/z1ans = -0.20000 + 0.60000ioctave:45> z1^2ans = 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
-4
-2
0
2
4
-4 -2 0 2 4
9:
octave:##> c=[1 2 -5 0 1 3];
tt roots
octave:12> roots([1 2 -5 0 1 3])ans =
-3.44726 + 0.00000i1.17303 + 0.39021i1.17303 - 0.39021i-0.44940 + 0.60621i-0.44940 - 0.60621i
15 Octave
Unix , Octave . , . Octave , ., hello :
#!octave-interpreter-name -qf# a sample Octave programprintf ("Hello, world!\n");
-
15 OCTAVE 38
( octave-interpreter-name Octave , /usr/bin/octave). #! . hello (e.g. chmod u+x hello),
hello
. #! , . #! Octave . Octave, -qf ,-q , f ~/.octaverc 7.
Octave , . Octave argv . :
#! /bin/octave -qfprintf ("%s\n", program_name ());arg_list = argv ();for i = 1:narginprintf (" %s\n", arg_list{i});
endforprintf ("\n");
test , :
kasion@tmp:$ chmod u+x testkasion@tmp:$ ./test arg1 arg2 arg3
:
kasion@tmp:$ ./test arg1 arg2 arg3testarg1arg2arg3
test PATH (/usr/bin /home/kasion/bin ), ls,cd test, shell script,., .
1.3000000000e+00 2.9549292750e+00 2.9349509600e+001.3102040816e+00 2.9454196710e+00 2.9248815610e+001.3204081633e+00 2.9359134520e+00 2.9148026660e+001.3306122449e+00 2.9264083650e+00 2.9047117190e+00
...7, Octave , path , -f ,Octave
.
-
15 OCTAVE 39
, TE TM .
D = C
d2neffd2 (5)
Getdistetm :
!/usr/bin/octave -q# no comments...#print the messagesclear all;printf("Programe name :%s\n", program_name ());printf("Processing ....\n");format long;#basic constantsC=3e2; # light speed in freespace [um/ps]#load the dataarglist=argv ();...#load the databuffer=load(arglist{1});lam=buffer(:,1);neffte=buffer(:,2);nefftm=buffer(:,3);
#caculate the dipersionfitorder=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);endd2neffte=polyval(P2te,lam);....outdata=[lam Dispersionte Dispersiontm];
#save the resultsave("-ascii",outfile,"outdata");#plot and save the figure;figure;plot(lam,Dispersionte,'k:','LineWidth',2,lam,Dispersiontm,'r-','LineWidth',2);...grid on;
-
A 40
print(figurename,'-dpng','-S680,500');printf("Done!\n");# End of the script
kasion@tmp:$ Getdistetm 800x500_bp_mode_neffr.dat
. shell ,
kasion@tmp:$ for file in `ls *neffr.dat`; do Getdistetm $file; done
neffr.dat .
A
:
Octave :http://www.gnu.org/software/octave/docs.htmlOctave:http://ljk.imag.fr/membres/Christophe.Prudhomme/courses/octave/octave-refcard-a4.pdfOctave :http://octave.1599824.n4.nabble.com/
B
Dr.P.J.G Long , Acknowledgements:
This document has been produced as a tutoial to acompany the version of Octave suppliedon the Cambidge-MIT Institute(CMI)8 funded Multidisciplinary Design Project (MDP)9 ResourceCD.
The text of this tutorial has been adapted from the student notes developed by Dr. PaulSmith from the Cambridge University Engineering Department for a 2nd year Introduction toMatlab sourse. Conversion from Paul Smiths original to this current document has be relativeeasy with in many cases needing only to exchange
Octave for Matlab in the text
the prompt and precise format of the answers given in the example scripts
removal of specific course administration.
However in number of cases there are significant differences, e.g. graphical performance (Gnuplotis assumed to be the output plugin for Octave), where changes have had to be made.
Any success of this tutorial is a major result of the the backgroud work carried out by TimFroggatt in setting up the MDP resource distribution and requests from Gareth Wilson, the authorof the RED Tools web interface for Octave scipts, for additional information and scripts.
8CMI-www.cambridge-mint.org9MDP-http://www-mdp.eng.cam.ac.uk
http://www.gnu.org/software/octave/docs.htmlhttp://ljk.imag.fr/membres/Christophe.Prudhomme/courses/octave/octave-refcard-a4.pdfhttp://octave.1599824.n4.nabble.com/
-
B 41
Significaant reference has been made to the resources generated and maintianed by John Eatonand his team at www.octave.org. As indicated above, the tutorial is heavily based on Paul SmithsOriginal in which he acknowledges advice and help from Roberto Cipolla, Richard Prager, HughHunt, Maurice Ringer, David Mansergh and Martin Szummer.
-
B 42
2011 , : Matlab Octave, , ,Octave , , LATEX , kile error , , , ::[email protected],
mailto:[email protected]
Octave?OctaveOctave(C++)
OctaveOctave
Octave
Multiple graphsMultiple figures
OctaveIPath
if...elseswitchforwhile
OctaveII1:2:
Ax=b3D
Octave