¼±¸·¼±„¹± ¼µ matlab

download ¼±¸·¼±„¹± ¼µ matlab

of 61

  • date post

    10-Oct-2014
  • Category

    Documents

  • view

    43
  • download

    4

Embed Size (px)

Transcript of ¼±¸·¼±„¹± ¼µ matlab

: MATLAB

..

2006

: 1. 1.1. 1.2. 1.3. 1.4. 1.5. 1.6. 2. 2.1. 2.2. 2.3. 2.4. 3. 3.1. 3.2. 3.3. 3.4. 4. 4.1. 5. 5.1. 5.2. 6. 6.1. 6.2. 6.3. 6.4. ; Matlab ; Command Window Matlab Matlab Matlab Gauss Gauss_Jordan Newton-Raphson 3 5 5 6 9 10 11 19 24 24 27 28 29 31 31 32 34 35 39 39 43 43 45 50 50 51 53 55 61

2

. . . . . Matlab. . . , . Computational Analysis . .

3

, . Matlab. , , . . , , e-mail.

.. enistaz@aegean.gr

4

1. 1.1.

-

. - . . . . , , . , , , . . , , . . .

5

, . . Matlab.

1.2.

Matlab ; Matlab

. - . . - . , , : (1) help (2) lookfor. Matlab . ,

6

. help. , . abs absolute=. Command Window Matlab:

help abs

:

ABS

Absolute value.

ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex modulus (magnitude) of the elements of X. See also SIGN, ANGLE, UNWRAP.

: () Matlab (.. C/C++) , , . () ( ), .. =+i, abs(X)=sqrt(^2+^2) .

7

() help ( abs). help . Matlab lookfor. . Matlab . . abs. Command Window Matlab:

lookfor absolute

help file absolute . lookfor, :

MAUIFINDEXE Return the absolute pathname to a MAUI executable. ABS Absolute value.

CIRCLEPICK Pick bad triangles using an absolute tolerance MAD Mean absolute deviation.

. help .

8

Matlab - . , help-file. Matlab (help lookfor) Command Window. ;

1.3.

Command Window Matlab; Matlab

. . components , . desktop Matlab x,y x,y version number . Command Window. Matlab - . , directory . , Editor.

9

1.4.

Matlab; Commad Window edit.

, Editor Matlab. Editor directory Matlab. , , . atlab . , Command Window, directory . , :

edit

directory :

cd sub-directory

sub-directory :

cd ..

Command Window Editor.

10

1.5.

Matlab; , Matlab

- . Editor. Editor , , directory . ,

File

,

Save as..

directory . directory work. , Command Window directory. . . deyterobathmia.m :

1:1 2 % We solve the Equation ax^2+bx+c=0 clear;

11

3 4 5 6 7 8 9

clc; close all;

a = 1; b = 1; c = 1;

10 D = sqrt(b^2-4*a*c); 11 12 p1 = (-b+D)/(2*a); 13 p2 = (-b-D)/(2*a); 14 15 p1r = real(p1); 16 p1i = imag(p1); 17 18 p2r = real(p2); 19 p2i = imag(p2); 20 21 fprintf('p1=%.4f %.4fi\np2=%.4f %.4fi\n',p1r,p1i,p2r,p2i);

: ( Editor) . % . , help. , Command Window : help deyterovathmia

12

, : We solve the Equation ax^2+bx+c=0 clear ( clear all) . clc , . close all . . . a 1, b 1 c 1. . , , x2+x+1=0. D. sqrt . , p1 p2. (p1r, p2r) (p1i, p2i) . . %.4f 4 f (float) . \n .

Matlab. , (..

13

C/C++) . : o (float, double, ) o ( C/C++, ) o compile Command Window. Matlab . Matlab . ( deyterovathmia2.m):

2:1 2 3 4 5 6 7 8 9 10 end 11 res = roots([a(1) a(2) a(3)]) for(i=1:1:3) fprintf('a%d =',i); a(i)=input(''); fprintf('\n'); % We solve the Equation a1x^2+a2x+a3=0 with the function roots clear; clc; close all;

14

2 1, . (.. input) ( a(i)). roots ( ) , . , . , Matlab. 33 . grammiko1.m :

3:1 2 3 4 5 6 7 8 9 10 for(i=1:1:3) 11 12 for(j=1:1:4) fprintf('a%d%d=',i,j); clear; clc; close all; % We solve the linear 3X3 system: % a11x + a12y + a13z = a14 % a21x + a22y + a23z = a24 % a31x + a32y + a33z = a34

15

13 14 15

a(i,j)=input(''); fprintf('\n'); end

16 end 17 18 for(i=1:1:3) 19 20 21 for(j=1:1:3) Dxyz1(i,j)=a(i,j); end

22 end 23 24 for(i=1:1:3) 25 26 27 28 29 30 31 32 for(j=1:1:4) if(j==4) k=1; else k=j; end Dx1(i,k)=a(i,j); end

33 end 34 35 for(i=1:1:3) 36 37 38 39 40 41 42 for(j=1:1:4) if(j==4) k=2; else k=j; end Dy1(i,k)=a(i,j);

16

43

end

44 end 45 46 for(i=1:1:3) 47 48 49 50 51 52 53 54 for(j=1:1:4) if(j==4) k=3; else k=j; end Dz1(i,k)=a(i,j); end

55 end 56 57 Dxyz = det(Dxyz1); 58 Dx = det(Dx1); 59 Dy = det(Dy1); 60 Dz = det(Dz1); 61 62 x = Dx/Dxyz; 63 y = Dy/Dxyz; 64 z = Dz/Dxyz; 65 66 fprintf('x=%.4f\ny=%.4f\nz=%.4f\n',x,y,z);

: help file ( 1-4). , ( 6-8).

17

a(i,j) 3 ( 10-16).

33 x,y,z.

det a(i,j) a i j .

, Matlab . , det. , input ( , ). 3 , , . . grammiko1a.m. , , . Matlab , . () .

18

1.6.

;

-. . , . , . directory , function . 3 . a11, a12, 34 x, y, z. . grammiko2.m, fun1.m fun2.m. , , 4 5 6 :

4:1 2 3 4 5 6 7 clear; clc; close all; %%% a11x + a12y + a13z = a14 %%% a21x + a22y + a23z = a24 %%% a31x + a32y + a33z = a34

19

8 9 10

li = 3; co = li+1;

11 [a]=fun1(li,co); 12 13 for(i=1:1:li) 14 15 16 for(j=1:1:co-1) Dxyz1(i,j)=a(i,j); end

17 end 18 19 for(i=1:1:li) 20 21 22 23 24 25 26 27 for(j=1:1:co) if(j==4) k=1; else k=j; end Dx1(i,k)=a(i,j); end

28 end 29 30 for(i=1:1:li) 31 32 33 34 35 36 for(j=1:1:co) if(j==4) k=2; else k=j; end

20

37 38

Dy1(i,k)=a(i,j); end

39 end 40 41 for(i=1:1:li) 42 43 44 45 46 47 48 49 for(j=1:1:co) if(j==4) k=3; else k=j; end Dz1(i,k)=a(i,j); end

50 end 51 52 fun2(Dxyz1, Dx1, Dy1, Dz1);

5:1 2 3 4 5 6 7 8 9 for(i=1:1:lin) for(j=1:1:col) fprintf('a%d%d=',i,j); b(i,j)=input(''); fprintf('\n'); end end function [b]=fun1(lin,col);

21

6:1 2 3 4 5 6 7 8 9 x = Dx/Dxyz; y = Dy/Dxyz; Dxyz = det(Dxyz2); Dx = det(Dx2); Dy = det(Dy2); Dz = det(Dz2); function a=fun2(Dxyz2, Dx2, Dy2, Dz2);

10 z = Dz/Dxyz; 11 12 fprintf('x=%.4f\ny=%.4f\nz=%.4f\n',x,y,z);

( 5 6) . , , . directory . . NXN . grammiko2a.m . Matlab .

22

. , , : (1) (2) (3) (4) (5)

23

2. 2.1.

Gauss Gauss

. , , . : , , . . . , , . , . : fun1.m 5. , a . Gauss 7 gauss1.m.

24

7:%%% a11x + a12y + a13z = a14 %%% a21x + a22y + a23z = a24 %%% a31x + a32y + a33z = a34

clear; clc; close all;

li = 3; co = li+1;

[a]=fun1(li,co);

[a]=fun3(li,co,a);

[r]=fun4(li,co,a);

for(j=1:1:li) fprintf('x%d=%.4f\n',j,r(j)); end

fun1.m fun3.m fun4.m . . 8 9 , fun3.m fun4.m:

25

8:function [a]=fun3(lin,col,a);

for(diag=1:1:lin-1) for(i=diag+1:1:lin) a_temp=-a(i,diag)/a(diag,diag); for(k=1:1:col) a(i,k)=a(i,k)+