student sample 499

Upload: adrsy

Post on 12-Jul-2015

78 views

Category:

Documents


0 download

TRANSCRIPT

)1-1( :MATLAB MATLAB MATLAB . MATLAB . MATLAB ) (Matrix Laboratory . Windows )1-1(

)1-1(:

)1-2( MATLAB : MATLAB )1- 1(. 52=22+3 63=45-09 966.2=58.0*41.3 7=8/65 652=8^2 + * \/or ^

)1-1(

: 2^3/2 >> = ans 2222.0 2^ )3/2( >> = ans 4444.0 4-4*3+2 >> = ans 01 4/3*2^2 >> = ans 3 )4+3(/)3*2(^2 >> = ans 9241.9

)1-3( : . MATLAB 1 1x . :Vectors . : 1. : :

]11,8,2,5,3[=>> x =x 3 5 2 11 8

. 2. :

]11;8;2;5;3[=>> x =x 3 5 2 8 );( . : ]3 2 1 0[=>> v =v 1 0 2 3

11

:

5=)4(>> v =v 0 1 2 5

:

)2(>> x=v =x 1 : )4:2(>> x=v =x 1 2 5

:

)4:2:2(>> x=v =x 1 5

:

)1:1-:3(>> x=v =x 2 1 0

:

]4,)4:1(>> v=[v =v 5 2 1 0 ])5:1(>> v=[-1,v 4

=v 4 5 2 1 0 1- ])4:3(>> v=[v(1:2),10,v =v 1- 0 01 1 2

: : :Length 1. : ]1- 4 1 0 5 2[=>> v =v 0 5 2 )>> length(v 1 4 1-

= ans 6 :Sum : )>> w=sum(v =w 11 :Max : )>> w=max(v =w 5 4. :Min : )>> w=min(v =w 1- :Size ]6,5,4;,3,2,1[=>> Matrix = Matrix 1 2 3 5.

2.

3.

4

5

6

)>> [Matrix]=size(Matrix = Matrix 2 3 6. :Sort ]3 8 5 7 9[=>> r =r 5 7 9 )>> s=sort(r =s 9 8 7 5 3 :Range )>> range(r = ans 6 : . : ;]5,3,1[=>> x ;]6,4,2[=>> y >> z=x+y =z 11 7 3 >> m=y-x =m 1 1 1 >> p=x.*y =p 03 21 2 2^.>> p=x =p 52 9 1 :Matrices ) (mxn m n . ]9,8,7;6,5,4;,3,2,1[=>> Matrix 7. 8 3

= Matrix 3 2 1 6 5 4 9 8 7 . ):,2(>> Matrix = ans 5 4 6 . )2,:(>> Matrix = ans 2 5 8 ):(>> Matrix = ans 1 4 7 2 5 8 3 6 9 : )2,1(>> Matrix = ans 2 : ] [ = )2,:(>> Matrix = Matrix 3 1 6 4 9 7 ] [ = ):,2(>> Matrix = Matrix 3 2 1 9 8 7 : ]21,11,01;9,8,7;6,5,4;,3,2,1[=>> Matrix

= Matrix 3 2 1 6 5 4 9 8 7 21 11 01 : )>> diag(Matrix = ans 1 5 9 ):(Transpose ] A = [aij n m A m n A A A A . A T ]6 4 2 ;5 3 1[=>> A =A 1 2 '>> A = ans 2 1 4 3 6 5 : ] A = [aij n ) det(A : 1 = det(A ) = a11 n 2 = det(A ) = a11a22 a12a21 nn 1= j

3 4

5 6

1. 2. 3.

2 > det( A ) = ( 1) j +1 a1 j det A1 j n ]9 8 7 ;0 5 4 ; 3 0 1[=>> A =A 3 0 1 0 5 4 9 8 7 )>> det(A = ans 63

:

: 1. : . )2,3(>> x=zeros =x 0 0 0 0 0 0

: 2. . )2,3(>> x=ones =x 1 1 1 1 1 1

3. : . )4(>> id=eye = id 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1

)1-4( :Matrix Algebra : : 1. :Sum : ]9,8,7;6,5,4;3,2,1[=>> x =x 1 4 7 2 5 8 3 6 9

)>> A=sum(x =A 21 51 81

)'>> A=sum(x =A 42 51 6 2. :Max : )>> B=max(x =B 7 8 9

)'>> B=max(x =B 3 6 9

3. :Size : )>> [C,D]=size(x =C 3 =D 3 : 1. : : ;]7,5;3,1[=>> A ;]8,6;4,2[=>> B >> C=A+B =C 3 11 7 51

3+>> C=A =C

4 8

6 01

2. : : >> C=A-B =C 1- 1- 1- 1- 3. : : >> C=A*B =C 82 02 67 25 4. )(: : 2^>> C=A =C 61 04 42 46

2^.>> C=A =C 1 52 9 94

)1-5( : MATLAB : 1. M-File . Matlab -M File .

m-files : . 13 . . .

Run . : m-file new m-file : )function y = sample(x 2^.x.^4-y=x+x

)2-1(: m-file

y 3=: x )3(>> sample = ans 96- ]-2,2[ : ;2:10.:2- = >> x ;))>> plot(x,sample(x

2 0 2- 4-

y-axsis

6- 8- 1- 0 1- 2 1- 4 2-

1- 5.

1-

0- 5.

0

0 5.

1

1 5.

2

x x -a is

)3-1(: 4^.y = x+x.^2-x

2. Matlab . Matlab : : . . )2-1(

Rem Floor Ceil Fix Round :

. . . . ) sec ( x ) csc ( x . . . .

Sin Cos Tan Cot Sec Csc Asin Acos Atan Acot

csc sec sin cos sinh cosh )3-1(

Acsc Asec Sinh Cosh Asinh Acosh

:

e

x

Exp Sqrt Abs Gcd Lcm Max Min Mod Rem Log 2log 01log Factorial Complex Conj Imag Real

. . =e : 3817.2 . 2 ) ) 01 . . . )4-1(

)1-6( :MATLAB : Matlab

Matlab . Matlab : . -D 2 . mesh .-D 3 meshc .-D 3 . -D 3 . .-D 3 hold on hold off . . . . .) ) . . . ) ) . . . )5-1(

plot 3Plot surf Surfc mesh ezplot meshgrid hold Title Xlabel Ylabel Zlabel grid on subplot Text Legend view axis contour

: B C M G Y K W R

)6-1(

: -Dashed .Dash dot : Dotted )7-1(

Solid

: ):(Absolute Error

: A.E: )1(....................... | * A .E =| p p p

* p ):(Relative Error : R.E: |*| P P = R .E 0 . P | |P )1( : :

2 :1.0 : 2 = y 1 = x cos x , y 2 = x sin x , x2 2

;2:1.0:2-=>> x ;)>> y1=x.^2.*cos(x);y2=x.^2.*sin(x ;)1>> plot(x,y >> hold on ;)2>> plot(x,y >> hold off )'>> xlabel('x-axis )'>> ylabel('y-axis >> grid on)1( figure 4 3 2 1 y axis 0 1- 2- 3- 4- 2-

:

1y 2y 5.1- 1- 5.0- 0 x axis 5.0 1 5.1 2

)4-1(: y 1 = x 2 cos x , y 2 = x 2 sin x )2( : 2^ x=-4:0.1:4 , y=x : ;4:1.:4-=>> x

>> y=x.^2; >> plot(x,y,'o')fig e 2 ur 1 6 1 4 1 2 1 0 8 6 4 2 0 -4

:

Y

-3

2

-1

0 X

1

2

3

4

y=x.^2 )5-1( :

: (3)2 2 z = 2xy /(x + y ), for ,x = 1: 0.1: 3, and ,y = 1: 0.1: 3

: >> [x,y]=meshgrid(1:0.1:3,1:0.1:3); >> z=2*x*y/(x^2+y^2); >> surf(x,y,z); >> xlabel('x') >> ylabel('y') >> zlabel('z')fig re 3 u

:

3 2 1 z 0 -1 -2 3 2 .5 2 1.5 y 1 1 2 1.5 x 2 .5 3

z = 2xy /(x 2 + y 2 ) )6-1( : >>contour(x,y,z) >> xlabel('x') >> ylabel('y')

fig r 3 ue .1 3 2 .8 2 .6 2 .4 2 .2 y 2 1 .8 1 .6 1 .4 1 .2 1 1

1 .2

1 .4

1 .6

1 .8

2 x

2 .2

2 .4

2 .6

2 .8

3

z = 2xy /(x 2 + y 2 ) )7-1( : :(4) ( cosn(x),sin(x : x=-10:.01:10; y1=sin(x); subplot(3,2,1) plot(x,y1);xlabel('x');ylabel('y');title('sin(x)') subplot(3,2,2) y2=cos(x); plot(x,y2,'r');xlabel('x');ylabel('y');title('cos(x)') subplot(3,2,3) plot(x,y1+y2,'k');xlabel('x');ylabel('y');title('sin(x)+cos(x)') y4=y2-y1; subplot(3,2,4) plot(x,y1,x,y4);xlabel('x');ylabel('y');title('cos(x)-sin(x)') y5=sin(x); y6=cos(x); subplot(3,2,5) plot(x,y5,'r',x,y6,'k');xlabel('x');ylabel('y');title('sin(x) and cos(x)')

sin (x) 1 y y 0 -1 -1 0 1 0 -1 -1 0

co s(x)

-5

0 x sin (x)+co s(x)

5

1 0

-5

0 x co s(x)-sin (x)

5

1 0

2 y y -5 0 5 x sin a d co (x) n s(x) 1 0 0 -2 -1 0

2 0 -2 -1 0 -5 0 x 5 1 0

1 0 -1 -1 0

y

-5

0 x

5

1 0

( cosn(x),sin(x )8-1(:

:(5) Z = sin(R ) R = x2+y2 R : >> [X,Y] = meshgrid(-8:.5:8); >> R = sqrt(X.^2 + Y.^2); >> Z = sin(R)./R; >> surf(X,Y,Z)figure 4

1

0.5 Z 0 -0.5 10 5 0 -5 y -10 -10 -5 x 5 0 10