Mat Lab Book

Click here to load reader

  • date post

    13-Apr-2015
  • Category

    Documents

  • view

    41
  • download

    5

Embed Size (px)

Transcript of Mat Lab Book

MATLAB0.5 0

-0.5 2 1 0 -1 -2 -2 -1 1 0 2

. - .

2007

& , 2007.

ISBN 978-9963-644-57-5 Kantzilaris Nicosia, Cyprus 2007

2007 . . , MATLAB. MATLAB. 7 11 . . http://www.ucy.ac.cy/~georgios http://www.ucy.ac.cy/~xenophontos m-files . . 2007 & 20537, 1678

v

vi

1. 1.11.1.1 1.1.2

MATLAB

1 24 7

1.2 1.31.3.1 1.3.2 1.3.3 1.3.4 1.3.5

quit exit clear clc help who whos save, load diary

12 1515 15 16 16 19

1.41.4.1 1.4.2 1.4.3

demo doc dir, ls what

2020 20 21

1.51.5.1 1.5.2 1.5.3

disp format input

2222 23 26

1.6 1.7 2. 2.12.1.1

28 31 35 3540

2.2 2.3 2.42.4.1

cat

42 46 5357

2.5 2.62.6.1

dot cross

59 6365

2.72.7.1

6770

2.8 3. 3.1 3.2 3.33.3.1 3.3.2

-FILES script feval

81 82 84 9093 96

3.3 4. 4.1 4.2 4.3

MATLAB for

99 103 104 111 120 vii

4.4 4.5 4.64.6.1

while if switch menu

120 122 127130

4.7 5. 5.15.1.1

IKA plot

132 137 137139

5.25.2.1

ezplot comet

143148

5.3 5.4 5.5 5.65.6.1 5.6.2 5.6.3 5.6.4 5.6.5 5.6.6

plot ,

148 150 153 156156 158 160 162 165 166

5.75.7.1

3

167169

5.8 5.9 6 6.1 6.2 6.3 6.4 7 7.17.1.1 7.1.2

polyfit pause ginput

174 176 185 185 187 191 200 203 203203 205

7.27.2.1

sprintf

207208

7.37.3.1 7.3.2 7.3.3 7.3.4 7.3.5

fopen fclose fprintf fscanf fgetl fgets fread fwrite

218218 219 221 224 224

7.4 8 8.1 8.2 8.3 8.4

Newton fzero

225 227 227 229 231 232 viii

9 9.1 9.29.2.1 9.2.2

Gauss LU H Gauss

233 233 235238 240

9.3 9.4 9.4.19.4.2

Cholesky

241 245245 246

9.5 9.69.6.1 9.6.2

Jacobi Gauss-Seidel

248 251251 253

9.7 10 10.1 10.210.2.1

Riemann trapz

254 257 257 263265

10.3 10.4 11 11.1 11.2 11.3 11.4

quad quadl ode45

268 270 273 273 277 279 282 285 287

ix

x

1

MATLAB (scientific computing). MATtrix LABoratory ( ). MATLAB (interactive) (data visualization) . Maple Mathematica, L . , . , MATLAB , , , . (. ) , , . MATLAB . MATLAB ( ) () MATLAB. MATLAB (finite-precision arithmetic), . Maple Mathematica. MATLAB. . ( ) MATLAB . . MATLAB help ()! , MATLAB: http://www.mathworks.com

. & .

1.1 MATLAB MATLAB . 6.5 :

. , , MATLAB (MATLAB opening window):

: 1) (Command Window) . MATLAB (prompt) >>. (). (Current Directory) . , Current Directory. Workspace Current Directory (workspace). , Workspace.

2)

3)

2

1.

4)

(Command History). Command History View. .

MATLAB (document windows), (graphics windows) (editing windows). :

: C:\Documents and Settings\youraccount C:\temp. : quit exit , [x] MATLAB, File Exit MATLAB .

( ). 6.5 MATLAB. version MATLAB .>> version ans = 6.5.1.199709 (R13) Service Pack 1

ver , (operating system), (compiler) (toolboxes) :

3

. & .

>> ver -----------------------------------------------------------------------------------MATLAB Version 6.5.1.199709 (R13) Service Pack 1 MATLAB License Number: 201749 Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 2) Java VM Version: Java 1.3.1_01 with Sun Microsystems Inc. Java HotSpot(TM) Client VM -----------------------------------------------------------------------------------MATLAB Version 6.5.1 (R13SP1) Financial Toolbox Version 2.3 (R13SP1) MATLAB Compiler Version 3.0.1 (R13SP1) Optimization Toolbox Version 2.3 (R13SP1) Signal Processing Toolbox Version 6.1 (R13SP1) Statistics Toolbox Version 4.1 (R13SP1) Symbolic Math Toolbox Version 3.0.1 (R13SP1)

1.1.1 MATLAB . : + * / 1.1.1>> 1+2 ans = 3 >> 3.14567-3 ans = 0.1457 >> 8/2.2 ans = 3.6364 >> 3*4 ans = 12 >> 3^4 ans = 81

4

1.

format compact . format 1.5. format compact :>> format compact >> 1+2 ans = 3 >> 3.14567-3 ans = 0.1457 >> 8/2.2 ans = 3.6364 >> 3*4 ans = 12 >> 3^4 ans = 81

(decimal notation) MATLAB ( ) (scientific notation). ( ) 0.0001234 4567.89 1.234 104 4.56789 103. MATLAB : 1.234e-4 4.56789e3 . e 10. 0.1234e-3 0.456789e4 . , Avogadro 6.022 1023 602200000000000000000000! 1.1.2 12345.67 0.000012345 1.234567 104 1.2345 105>> 1.234567e4+1.2345e-5

5

. & .

ans = 1.2346e+004

. format long:>> format long >> 1.234567e4+1.2345e-5 ans = 1.234567001234500e+004

e e . MATLAB ( )! 1.1.3 1.2 105. e e MATLAB>> 1.2 e-5 ??? 1.2 e-5 | Error: Missing operator, comma, or semicolon. >> 1.2e -5 ??? 1.2e -5 | Error: "End of Input" expected, "incomplete floating-point number" found.

:>> 1.2e-5 ans = 1.2000e-005

FORTRAN C, MATLAB : 1. . 2. . 3. . 4. , . 1.1.4 : 1.12+3 1 3 2

6

1.

>> (1.1^(2+3)-1)/(3*2) ans = 0.1018

:>> (1.1^2+3-1)/(3*2) ans = 0.5350 >> (1.1^(2+3)-1)/3*2 ans = 0.4070

1.1.2 =. 1.1.5>> x=1 x = 1 >> y=2 y = 2 >> w=z^y w = 9

. MATLAB . y Y . : ( ). , (underscore). MATLAB (.. ). . 1.1.6>> Y=20.2 Y = 20.2000 >> y=2; :>> Y+y ans = 22.2000

MATLAB . ; (semicolon). , .

7

. & .

1.1.7>> x=1.234567 x = 1.2346 >> y=2006; >> z=x/y; >> y y = 2006 >> z z = 6.1544e-004

( ). 1.1.7 ()>> x=1; y=2, z=3; sum=x+y+z, w=x*y*z; y = 2 sum = 6

y sum . , ans. . 1.1.7 ()>> y-2000 ans = 6 >> ans^2 ans = 36 >> ans/10 ans = 3.6000

MATLAB , . (strings) 1 , (logical), . true () false ().1

string ( alphanumeric) .

8

1.

MATLAB . :

a+bi a b i : i = 1 . z z'. 1.1.8

z1= 1 + 4i z2 = 2 3i. : z1 + z2, z1 z2, z2/z1, z1 , z2 ( z1 z2 ) .>> z1=1+4i z1 = 1.0000 + >> z2=2-3i z2 = 2.0000 >> z1+z2 ans = 3.0000 + >> z1*z2 ans = 14.0000 + >> z1' ans = 1.0000 >> z2' ans = 2.0000 + >> (z1-z2)' ans = -1.0000 -

4.0000i

3.0000i

1.0000i

5.0000i

4.0000i

3.0000i

7.0000i

MATLAB . MATLAB ( 3) , 11 1n . ( ) 2. MATLAB ( ). MATLAB :1. [ .. ]. 11 , . (!), . 2. . 3. (;) MATLAB.

.9

. & .

1.1.9

u = (4, 0, 1, 2) v = (1, 2, 3, 1).>> u=[4 0 -1 2]; >> v=[1, 2, -3, 1]; >> u+v ans = 5 2 -4

3

u v . . 1.1.10

3 + 2B 1 0 2 5 4 0 A= B = 0 3 1 1 3 6 >> A=[-5 4 0 1 -3 6] A = -5 4 1 -3

0 6

>> B=[1 0 -2; 0 3 1] B = 1 0 -2 0 3 1 >> 3*A+2*B ans = -13 12 3 -3

-4 20

A B . . 1.1.11

uv vu u = [1 1 4]>> u=[1 -1 4]; >> v=[-3;0;2]; >> u*v ans = 5 >> v*u ans = -3 3 -12 0 0 0 2 -2 8

3 v = 0 2

10

1.

MATLAB . 1.1.12>> stringvar='Keimeno se 1 grammi' stringvar = Keimeno se 1 grammi >> stringvar2='Lastname firstname' stringvar2 = Lastname firstname

MATLAB . true () MATLAB 1 false () 0. true, logical(1) logical(true) 1, false, logical(0) logical(false) 0. 1.1.13>> x=true x = 1 >> y=false y = 0 >> logical(true) ans = 1 >> logical(1) ans = 1 >> logical(false) ans = 0 >> logical(0) ans = 0

11

. & .

1.2 MATLAB o , , , , . . sin cos tan asin acos atan exp log log10 abs sqrt mod rem round ceil floor fix 10 (modulus)

MATLAB C FORTRAN, sin, exp, sqrt, log . help elfun MATLAB (elementary math functions). help specfun

(specialized math functions) MATLAB. 1.2.1