Система MATLAB

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

ɆɂɇɂɋɌȿɊɋɌȼɈ ɈȻɊȺɁɈȼȺɇɂə ɊɈɋɋɂɃɋɄɈɃ ɎȿȾȿɊȺɐɂɂ ȽɈɋɍȾȺɊɋɌȼȿɇɇɈȿ ɍɑɊȿɀȾȿɇɂȿ ɄɍɁȻȺɋɋɄɂɃ ȽɈɋɍȾȺɊɋɌȼȿɇɇɕɃ ɌȿɏɇɂɑȿɋɄɂɃ ɍɇɂȼȿɊɋɂɌȿɌ ɄȺɎȿȾɊȺ ȼɕɑɂɋɅɂɌȿɅɖɇɈɃ ɌȿɏɇɂɄɂ ɂ ɂɇɎɈɊɆȺɐɂɈɇɇɕɏ ɌȿɏɇɈɅɈȽɂɃ

Ɇ.Ⱥ.Ɍɵɧɤɟɜɢɱ

ɋɢɫɬɟɦɚ MATLAB ɋɩɪɚɜɨɱɧɨɟ ɩɨɫɨɛɢɟ ɤ ɤɭɪɫɭ “ɑɂɋɅȿɇɇɕȿ ɆȿɌɈȾɕ ȺɇȺɅɂɁȺ” ɞɥɹ ɫɬɭɞɟɧɬɨɜ ɫɩɟɰɢɚɥɶɧɨɫɬɢ «ɉɪɢɤɥɚɞɧɚɹ ɢɧɮɨɪɦɚɬɢɤɚ ɜ ɷɤɨɧɨɦɢɤɟ»

Ʉɟɦɟɪɨɜɨ 2002

1

ȼɜɟɞɟɧɢɟ ɜ MatLab (ɩɪɨɢɫɯɨɠɞɟɧɢɟ ɢ ɜɨɡɦɨɠɧɨɫɬɢ) Э



,

)

-

, , ,

,

,

. , , , ,

Э .

Э

(

(

)

, ) “ ” 2000-4000 ( , , “ ”

,

/

Э ( 2048 43) ,

, -

,

).

-

( ) . ,

, -

. (

,

-

.), ( ,

,

). ,

.

-2 (

-22)

-

-20 Э

.

2



,

-60 -

,

, 30 – Maple, Mathematica, MathCad, MatLab . , , , – . . . MatLab (Matrix Laboratory) , , ,

-

, ,

,

)

,

,

, -

, ,

.

. . М. (

-

,

. Microsoft Word, .

Pascal’

, Visual Basic’ , MatLab’

,

2-3

( ).

,

-

, .

1. Ɋɟɠɢɦ ɤɨɦɚɧɞɧɨɣ ɫɬɪɨɤɢ. Ɏɨɪɦɚɬɵ ɞɚɧɧɵɯ MatLab

, ,

-

, .

“»”) ,

, .

, я

( ,

-

3

(

) ,

,

Enter,

(answer). ( ) a=3.2 a = 3.20000000000000 ( ɚ 3.2), sin(a)/a ans = -0.01824191982112. , ( , ; _ ) -

! , . , ,

),

(

Enter

.

clr. ,

, (

, matlab/elfun –

)

.

, ,

,

-

Word. . (Pref-

erence)

(File) (General)

meric Format , Long – Bank – tional –

15, ShortE ( (

. : Short – , Hex – LongE –

Loose

Nu5, , Ra– ), -

Compact), . ( ommand Window Font) 6 : Font ( ), Style (Light, Regular , Bold – ), Size ( 10, 12 15), BackGround Color ( ) , Color ( ) . , MatLab’e , (array). 6 ( ):

4

• •



(double); (char),



; (sparse),

(cell), 0 255 (uint8).

(struct)

. (

, .

;

, 2×3 -

» b=[1 2 3] – ; d=zeros(4,7) -

-

) » a=[1 2 3; 4 5 6] » b=[1; 2; 3] 4×7

;

. , k-

, (k,3) .

, a(:,3) –

,

: » a=[1 2 3; 4 5 ] : Number of elements in each row must be the same. (Ч

) ,

: ;

-

; -

( ). i:k i:j:k : j,

, -

“ i k 1” t=-pi:0.01:pi p=0:8 ( , q=3:1).

, : zeros(n), zeros(m,n), zeros(m,n,p,..), zeros(size( )) ( , , ); ones(n), ones (m,n), ones (size( )) . , , ( ):

– -

-

-

5

+A -A A+B A-B A .*B A.\ B A ./B A .^B

m

A\B = -

c : B – m×k { (B’/A’)’ }

– ( (

) ) ( ,

A^k

k=0 –

k0 ;

k R

T

D

A^k= R D.^k/R

- A’

A.’

( )

ɋɢɫɬɟɦɚ ɪɚɛɨɬɚɟɬ ɩɥɟɤɫɧɵɦɢ ɱɢɫɥɚɦɢ » a=1+2i a = 1.0000 + 2.0000i » b=1-3i b = 1.0000 - 3.0000i » a*b ans = 7.0000 - 1.0000i » exp(ans) ans = 592.51 -922.78 i

)

,

: A < B , A B , A>= B ), A == B, A~=B ( / ), ( ) . : ~A, - ) A&B, (

who

( whos:

,

,

ɫ ɤɨɦi, j:

( -

( -

(

-

– ) A|B. . . ɪɚɛɨɱɟɣ ɨɛɥɚɫɬɢ, )

» who Your variables are: i r t » whos Name Size Bytes Class i 1x1 8 double array r 4x629 20128 double array t 1x629 5032 double array Grand total is 3146 elements using 25168 bytes

6

(save) save myfile v1 v2 v1 v2, save myfile du*rak – du

(load) . myfile , rak.

clear - clear
.

2. ɗɥɟɦɟɧɬɚɪɧɵɟ ɦɚɬɟɦɚɬɢɱɟɫɤɢɟ ɮɭɧɤɰɢɢ . . . , . pi = 4*atan(1)=imag(log(-1))=3.1415926535897..; abs(X) – : a+bi 2 a + b / abs(3-4i)=5 , abs(-13)=13; angle(X) – ( [-π,π]): iϕ a = r cosϕ, b = r sin ϕ: X=a+bi r⋅e , » angle(3+4i) ans = 0.9273 ; » angle(1) ans = 0 ; » angle(4+3i) ans = 0.6435 ; real(X), imag(X) – ; conj(X) – : » conj(2+3i) ans = 2.0000 - 3.0000i ; ceil(X), fix(X), floor(X), round(X) ( , ; ; , ; ); mod(X,Y) X Y; sign(X) – ( X / |X|); gcd(m,n) – ; [g,c,d]=gcd(m,n), c,d , g==m*c+n*d : » f=gcd(18,27) f= 9 » [g,c,d]=gcd(18,27) g = 9 c = -1 d = 1 ; lcm(m,n) – : » lcm(34,51) ans = 102 ; rat(X) , rat (X,k) – |X|⋅10-6 ): |X|⋅10-k/2 ( » rat(12.5) ans =13 + 1/(-2) » rat(12.546) ans =13 + 1/(-2 + 1/(-5 + 1/(15))) ; rats(X), rats(X,k) – :

7

» rats(12.546) ans = 2045/163 ; sqrt(X) – : » sqrt(5) ans = 2.2361 » sqrt(3+4i) ans = 2.0000 + 1.0000i; exp(X) – ex (ex+iy= ex(cos y+i siny)) : » exp(1) ans = 2.7183 » exp(2+i) ans = 3.9923 + 6.2177i ; pow2(X) – 2x; log(X) – ; log2(X), log10(X) – 2 10; sin(X) cos(X) tan(X) cot(X) csc(X) sec(X) – ( , , , , , ): sin(x+iy)=sin(x) ch(y) +i cos(x) sh(y); cos(x+iy)=cos(x) ch(y) -i sin(x) sh(y), tg (X)= sin(X)/ cos(X) ; ctg(X)=cos(X)/sin(X); cosec(X)=1/sin(X); sec(X)=1/ cos(X) : » sin(pi/2) ans = 1 ; » sin(3+4i) ans = 3.8537 -27.0168i ; asin(X) acos(X) atan(X) acot(X) acsc(X) asec(X) – ( , . .): » asin(1/sqrt(2)) ans = 0.7854 ; » asin(3+4i) ans = 0.6340 + 2.3055i ; atan2(Y,X) Arctg ( ), [-π,π]; sinh(X) cosh(X) tanh(X) coth(X) csch(X) sech(X) – ( , , , , , X -X X -X ): sh(X)=(e -e )/2 , ch(X)=(e +e )/2 .; asinh(X) acosh(X) atanh(X) acoth(X) acsch(X) asech(X) – : arsh( X ) = ln( X + X 2 + 1 ) , arch( X ) = ln( X + X 2 − 1 )

arth( X ) = 21 ln 11+− XX ,

arcth( X ) = 21 ln 11+− XX ,

arcsch(X)=arsh(1/X), arsech(X)=arch(1/X); erf ( )( )

erf ( x ) =

π

2

,

-

−t ∫ e dt x

2

0

:

erfc( )=1-erf(x) ( erfcx( )=exp(x2)⋅erfc(x) ( ); erfinv( ) ( , );

); -

8

gamma( ) -



Γ ( x ) = ∫ e −t t x −1 dt (

-

-

0

(1+ )= !) » gamma(5) ans = 24 » gamma(0) Warning: Divide by zero ( ans = Inf ( » gamma(0.5) ans = 1.7725 » gamma(-0.5) ans = -3.5449 » gamma(0.1) ans = 9.5135 : gammainc(x,a)=

P( x , a ) =

); gammaln(x)=ln ( ) (

1 Γ(a)

). )

− t a −1 ∫ e t dt ( x

0

-

);

Γ ( x )Γ ( y )

B( x , y ) = ∫ t x −1( 1 − t ) y −1dt = Γ ( x + y ) 1

beta(x,y) -

-

-

0

-

;

ɮɭɧɤɰɢɢ ɩɪɟɨɛɪɚɡɨɜɚɧɢɹ ɤɨɨɪɞɢɧɚɬ: (X,Y) (r,ϕ): r=(X2+Y2)1/2, ϕ=Arctg(Y/X) – [ϕ,r]=cart2pol(X,Y); (X,Y,Z) (r,ϕ,Z) [ϕ,r,Z]=cart2pol(X,Y,Z) ; (r,ϕ,θ) : r=(X2+Y2+Z2)1/2, ϕ=Arctg(Z/ (X2+Y2)1/2), θ=Arctg(Y,X) - [θ,ϕ,r]=cart2sph(X,Y,Z); (pol2cart): X=r⋅cos(ϕ), Y=r⋅sin(ϕ) ; (sph2cart): Z=r⋅sin(ϕ), X=r⋅cos(ϕ)⋅cos(θ), X=r⋅cos(ϕ)⋅sin (θ) ( , ); ɫɩɟɰɢɚɥɶɧɵɟ , ;

ɮɭɧɤɰɢɢ ( Э , ,

, ,

-

, ), ɮɭɧɤɰɢɢ ɥɢɧɟɣɧɨɣ ɚɥɝɟɛɪɵ, ɚɩɩɪɨɤɫɢɦɚɰɢɢ ɞɚɧɧɵɯ, ɱɢɫɥɟɧɧɨɝɨ ɢɧɬɟɝɪɢɪɨɜɚɧɢɹ, ɩɨɢɫɤɚ ɤɨɪɧɟɣ ɭɪɚɜɧɟɧɢɣ, ɨɛɫɥɭɠɢɜɚɧɢɹ ɝɪɚɮɢɤɢ, ɨɛɪɚɛɨɬɤɢ ɞɚɬ, ɦɧɨɠɟɫɬɜ .

9

,

-

1

: » t=-pi:0.01:pi; % -π

π

0.6 0.4

0.01 );

(

» e=sin(t);

0.8

0.2 0

%

-0.2 -0.4

; » plot(t,e)

-0.6

%

-0.8

.

-1 -4

-3

-2

-1

0

1

2

3

4

3. Ɋɟɠɢɦ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ

-

File ) Open(

MatLab’ : New ( -

.m). ( , .). -

:



-

-

.

, (

,

-

%) .

script -

. , .

-

. :

function [< < ,

>]= > (
) fact.m:

function [f, g]=fact(n) % f=prod (1:n); g=1/f; , MatLab’ ɍɫɥɨɜɧɵɣ ɨɩɟɪɚɬɨɪ

. :

10

if



end

>

if


< elseif < < else < end

else end

> > > > , -

. , , ( – 1, – 0). Ɉɩɟɪɚɬɨɪ ɰɢɤɥɚ ɫ ɡɚɞɚɧɧɵɦ ɱɢɫɥɨɦ ɩɨɜɬɨɪɟɧɢɣ, : for V=A :H:B for V=A:B < > < > end end (V – / , A,B – ; H – , 1). , :

-

for i=1:n-1 for k=i+1:n if a(i) > ,

.

,

(

-

11

)

break:

while a250 break end ...

Ɉɩɟɪɚɬɨɪ ɩɟɪɟɤɥɸɱɟɧɢɹ

:

switch < case < < case < < ..... otherwise < end

> 1> > 2> > % > -

: swith k case 0 t=1 case (1, 2,5) t=2 otherwise t=0 end

ȼɵɯɨɞ ɢɡ ɮɭɧɤɰɢɢ return. , , .

ȼɜɨɞ ɫ ɤɥɚɜɢɚɬɭɪɵ < >= input (‘ ’) , » x=input(' '); 3 ɉɪɢɨɫɬɚɧɨɜɤɚ ɜɵɩɨɥɧɟɧɢɹ ɩɪɨɝɪɚɦɦɵ pause ( ), pause (n) ( (

n

), keyboard return).

12

ɦɟ-

ɧɸ:
=menu(‘ , :

’,’

k=menu(‘

’,’

1’,’

’,’

2’,...)

’,’ k,

1, 2

’) -

3. , (

disp, ,

fprint),

-

. . 1.

-

y n = ( −1 )

n +1

,

nn

.

0.0001) -

,

(

y.m):

function f=y(n) if mod(n,2)==0 f=-1; else f=1; end f=f/n^n; end

(

limit1.m):

n=1 ; while abs(y(n))>1e-4 n=n+1 ; end disp(' k=n for x=1:k Y(x)=y(x); end disp(' Y plot(1:k,Y, 'r-*' ) %

')

') -

(-)

®,

(*)

13 1

0.8

-

limit1,

0.6

0.4

k,

0.2

Y (n=1÷k)

0

-0 . 2

-0 . 4

1

1.5

2

2.5

3

3.5

4

4.5

5

5.5





:

6

k =6 Y = 1.0000 -0.2500 0.0370 -0.0039 0.0003 -0.0000

2.

.



∑ ( −1 )m −1 ( 2 m −1 )⋅1( 2 m −1 )!

-6

m =1

10 . limit2.m ( ): y=1; s=y ; m=1; while abs(y)>1e-6 y=-y*(2*m-1)/(2*m+1).^2; s=s+y; m=m+1 ; end disp(' ') disp( m-1) disp(' ') disp(s) limit2 , , 10-6

:

6 0.90097107966794

4. Ɉɩɟɪɚɰɢɢ ɧɚɞ ɦɚɫɫɢɜɚɦɢ ( =[1 3 5 7; 4 5 6 7] (2

, )

, 4

), =[1; 3; 5; 7] (

4

14

)

( )

[1:2:7], [4:7], [ [1:2:7]; [4:7] ]

. . -

: A(2,k) – A(:,k) - kA(1:3; 1:4) –

k-

;

; 3

4

-

; C(:, :, 12) –12-

. ,

.

, , A(13:17) –

13

, A(:) –

-

17.

ɨɛɴɟɞɢɧɹɬɶ ɦɚɫɫɢɜɵ “ɩɨ ɝɨɪɢɡɨɧɬɚɥɢ”[A, B, C] [A B C] ( ) “ɩɨ ɜɟɪɬɢɤɚɥɢ” -[A; B;C] ( ). ɭɞɚɥɢɬɶ ɨɞɢɧɚɤɨɜɵɟ ɷɥɟɦɟɧɬɵ unique(X). ɨɛɴɟɞɢɧɟɧɢɹ - union(X,Y), ɩɟɪɟɫɟɱɟɧɢɹ - intersect(X,Y), ɪɚɡɧɨɫɬɢ – setdiff(X,Y): » a=[1 2 3 6]; » b=[1 3 7];

» union(a,b) ans = 1 2 3 6

»intersect(a,b) ans = 1 3

7

k=find(X
) (

» k=length('Э k = 10

» k=find(X) k= 1 3 4

5

ɞɥɢɧɵ ɜɟɤɬɨɪɚ ')

6

» X=[ 1 0 -3 6 7 13]; » k=length(X) k= 6

ɪɚɡɦɟɪɨɜ ɦɚɫɫɢɜɚ – » X =[ 1 0 –3 ; 6 7 13] » k=size(X) k= 2 3

,

» k=find(X==0 | X),

»[i,j]=find(A>0& A chol R= 1 2 Matrix must be positive definite 0 1 p= 3

(det( )= -3) , , q=2 R′R . [Q,R]=qr(A), [Q,R,P]=qr(A), [Q,R]=qr(A,0) ɪɚɡɥɨɠɟɧɢɟ m×n: [Q,R]=qr(A) – A=QR (Q*Q'=E) R: C= 1 2 3 t= 1 5

0 1 0

-

QR-

» [Q,R]=qr( ) Q = -0.2672 -0.0514 -0.9622 R = -3.7416 -7.2160 -9.0868 -0.5345 -0.8229 0.1924 0 -1.3887 -0.3086 -0.8017 0.5657 0.1924 0 0 -0.5773 R= » [Q,R]=qr(t) -5.0990 -3.5301 -1.9611 Q = -0.1961 -0.9805 0 -2.3534 -4.7068 -0.9805 0.1961

Q

20

[Q,R,P]=qr(A)

[Q,R]=qr(A,0) Q.

m>n

R (A*P’=Q*R); ,

n

QR[Q1,R1]=qrdelete(Q,R,k), ,

k. [Q1,R1]=qrdelete(Q,R,k,X), ,

QR-

k . X=nnis(A,B), X=nnis(A,B,t) ɪɟɲɟɧɢɟ ɫɢɫɬɟɦɵ = ɦɟɬɨɞɨɦ ɧɚɢɦɟɧɶɲɢɯ ɤɜɚɞɪɚɬɨɜ, , norm(A*X-B) ε t=max(m,n)*norm(A,1)* ε. ɜɵɱɢɫɥɟɧɢɹ ɫɨɛɫɬɜɟɧɧɵɯ ɱɢɫɟɥ ɢ ɜɟɤɬɨɪɨɜ. =λX d=eig(A) [X,d]=eig(A) (d, – ): a= 1 1 1

2 4 8

3 9 27

» d=eig(a) » [R,d]=eig(a) R= d= 0.8484 0.7163 -0.1198 0.2179 -0.5150 0.6563 -0.3295 1.8393 0.1222 -0.2371 -0.9365 29.9428

d= 0.2179 0 0 0 1.8393 0 0 0 29.9428

( )

A*X=R*D:

(

» a*R-R*d ans = 1.0e-014 * 0.0583 0.0666 -0.7549 0.0166 -0.0444 -0.5329 0.0902 -0.3886 -0.7105 d=eig(A,B) [V,D]= eig(A,B) )

=λBX.

QR, 30⋅n, Solution will not converge (

-

-

). -

21

(A0+λA1+λ2A2+...+λpAp)X=0 [R,d]=polyeig(A0,A1,.., Ap), Rn×(n×p) . =0 eig(A0) , =1 – eig(A0,-A1) n=1 ( ) – roots(Ap,...,A1,A0), p 2 Apλ +...+ A2λ +A1λ +A0=0. ɫɢɧɝɭɥɹɪɧɨɝɨ ɪɚɡɥɨɠɟɧɢɹ ɦɚɬɪɢɰɵ s=svd(A), [U,S,V]=svd(A), [U,S,V]=svd(A,0) m×n (m≥n) A=U*S*V′, U′*U=V*V′=E, S=diag(s1,s2,...,sn). U n n ′, V – ′ ; S ′ ( ).

6. Ɉɩɟɪɚɰɢɢ ɧɚɞ ɩɨɥɢɧɨɦɚɦɢ Pn(x)=p1xn+p2xn-1+...+pnx+an+1 . – n+1–

,

. ɜɵɱɢɫɥɟɧɢɢ ɡɧɚɱɟɧɢɣ ɩɨɥɢɧɨɦɚ polyval(P,X): » polyval([1 2 5],[0 3 1]) ans = 5 20 8

» polyval([1 2 5],[0 3 1; 1 1 1]) ans = 5 20 8 8 8 8

polyvalm(P,X)

ɦɚɬɪɢɱɧɨɝɨ ɩɨɥɢɧɨɦɚ : » polyvalm([1 2 5],[0 3 1; 1 1 1; 0 0 2]) ans = 8 9 7 3 11 6 0 0 13 ɍɦɧɨɠɟɧɢɟ ɩɨɥɢɧɨɦɨɜ m+n(x)=Pm(x) × Qn(x) C=conv(P,Q) –

Ck =

Ⱦɟɥɟɧɢɟ ɩɨɥɢɧɨɦɨɜ [C,R]=deconv(A,B) , – » conv([1 2 3],[5 6]) ans = 5 16 27 18

∑A

ɡɧɚɱɟɧɢɹ

-

min( k ,m )

j k + 1− j j = max( 1 ,k + 1− n )

B

.

R– » [c,r]=deconv([1 2 3],[5 6]) c = 0.2000 0.1600 r= 0 0 2.0400

.

22

ȼɵɱɢɫɥɟɧɢɟ ɩɪɨɢɡɜɨɞɧɵɯ ɨɬ ɩɨɥɢɧɨɦɚ, ɩɪɨɢɡɜɟɞɟɧɢɹ ɢ ɨɬɧɨɲɟɧɢɹ ɩɨɥɢɧɨɦɨɜ dp=polyder(P), dc=polyder(A,B) [f,g]=polyder(A,B): » polyder([1 -2 3 4 5]) ans = 4 -6 6 4

» polyder([1 2 3],[5 6]) » [f,g]=polyder([1 2 3],[5 6]) ans = f = 5 12 -3 g = 25 60 36 15 32 27

ȼɵɱɢɫɥɟɧɢɟ ɤɨɪɧɟɣ ɩɨɥɢɧɨɦɚ ɩɨɫɬɪɨɟɧɢɟ ɩɨɥɢɧɨɦɚ ɩɨ ɟɝɨ ɤɨɪɧɹɦ –

roots(P), poly(R).

» poly(r) ans = 1.0000 3.0000 5.0000 7.0000

» r=roots([1 3 5 7]) r = -2.1795 -0.4102 + 1.7445 i -0.4102 - 1.7445 i

poly(Ⱥ) ɫɤɨɝɨ ɩɨɥɢɧɨɦɚ |λE-A|=0 (

ɩɨɫɬɪɨɟɧɢɟ ɯɚɪɚɤɬɟɪɢɫɬɢɱɟ):

.

» A= magic(3) A= 8 1 6 3 5 7 4 9 2

» P=poly(A) P= 1.0e+002 * 0.0100 -0.1500 -0.2400 3.6000

,

-

, Pm ( s ) Qn ( s )

sk m,

= ∑ n

rk s − sk

k =1 Qn(s);

∑ m

:

+ f ( s ), sj

r j + i −1

i = 1( s − s j ) [r,s,f] =residue(P,Q) ɪɚɡɥɨɠɟɧɢɟ ɨɬɧɨɲɟɧɢɹ ɩɨɥɢɧɨɦɨɜ ɧɚ ɩɪɨɫɬɵɟ ɞɪɨɛɢ ( ). rj=resi2(P,Q,sj,m,j), j – ( j=m); m=1 ( ). [P,Q] =residue(r,s,f) . i

[r,s,f]=residue([1 -6 11 -6],[1 -5 4 0]) » [A,B]=residue([0.5 0 -1.5],[4 1 0],[1]) A = 1 -6 11 -6 r = 0.5000 0 -1.5000 B = 1 -5 4 0 s= 4 1 0 f= 1

23

,

s 3 − 6 s 2 + 11 s − 6 s 3 −5 s 2 +4 s

=

» P=poly([1 2 3 ]) P = 1 -6 11 -6 » Q=poly([0 0 0 6]) Q = 1 -6 0 0 0 » [r,s,f]=residue(P,Q) r = 0.2778 0.7222 -1.6667 1.0000 s= 6 0 0 0 f = []

:

s 3 − 6 s 2 + 11 s − 6 s 4 −6 s 3

=

0.2778 s −6

0.5 s −4

+

0 s −1

− 1s.5 + 1

» r1=resi2(P,Q,0,3,1) r1 = 0.7222 » r2=resi2(P,Q,0,3,2) r2 = -1.6667 » r3=resi2(P,Q,0,3,3) r3 = 1 1.667 + 0.7222 − + s s2

1 s3

7. Ʉɨɥɥɟɤɰɢɹ ɬɟɫɬɨɜɵɯ ɦɚɬɪɢɰ ,

.

hadamard (n) – –1); n » hadamard (4)

( n/20

n, n/12

1 2:

ans =1 1 1 1 1 -1 1 -1 1 1 -1 -1 1 -1 -1 1

hij=1/(i+j-1)

hilb (n), invhilb(n) – ( , »A=hilb(3) A = 1.0000 0.5000 0.3333 0.5000 0.3333 0.2500 0.3333 0.2500 0.2000

magic(n) – 1 n2 » magic(2) ans = 1 4

:

):

» B=invhilb(3) B= 9 -36 30 -36 192 -180 30 -180 180

» det(A) ans = 4.6296e-004

(

):

3 2

» magic(3) ans = 8 1 3 5 4 9

6 7 2

24

(1+ )j ( 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

pascal(n) –

» pascal(3) ans = 1 1 1 2 1 3

)

» pascal(5) ans = 1 1 1 1 1

1 3 6

rosser

-

(

-

1 1 1 2 3 4 3 6 10 4 10 20 5 15 35

8-

1 5 15 35 70

, -

): 611 196 192 407 8 52 49 29

196 899 113 -192 -71 -43 -8 -44

-192 113 899 196 61 49 8 52

407 -8 -52 -192 -71 -43 196 61 49 611 8 44 8 411 -599 44 -599 411 59 208 208 -23 208 208

-49 -8 8 59 208 208 99 -911

,

29 -44 52 -23 208 208 -911 99

,

-

): 1000 1000

1020.049

1020.000

1019.902 0.098 0 -1020.049

toepliz(ɏ) –

, ;

toepliz(ɏ,Y) – Y(

≠ 1,

, X -

1

X): » x=[1 3 5 7]; » toeplitz(x) ans = 1 3 3 1 5 3 7 5

5 3 1 3

7 5 3 1

» x=[1 3 5 7]; » y=[1 11 21 31]; » toeplitz(x,y) ans = 1 11 21 3 1 11 5 3 1 7 5 3

» x=[1 3 5 7]; » y=[-1 -11 -21 -31]; » toeplitz(x,y) 31 Column wins diagonal conflict. 21 ans = 1 -11 -21 -31 3 1 -11 -21 11 5 3 1 -11 1 7 5 3 1

25

(

wilkinson(n) n-

-

,

n=21,

; ); vander(X) – n

( n-j

Vij=xi ): x= [1 2 3 5] » vander(x) ans = 1 8 27 125

» wilkinson(4) ans = 1.5000 1.0000 0 0 1.0000 0.5000 1.0000 0 0 1.0000 0.5000 1.0000 0 0 1.0000 1.5000

1 1 4 2 9 3 25 5

1 1 1 1

,

-

: >]= gallery(‘

[
) 0.05 < >( 1,X2) ; < 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 > - quad quad8. . 8.5

2

30

8.5. ɇɭɥɢ ɢ ɷɤɫɬɪɟɦɭɦɵ ɮɭɧɤɰɢɣ , –

.

F ( X ) = ∑ fi 2 ( X ) ,

fi(X)=0, i=1,...,n

n

-

i =1

,

.

,

-

. : -

-

roots(...) .

. -

. xmin=fmin(‘ fmin (‘ ’, a,b,<
), option(2)-

’,a,b), xmin=fmin(‘ ’,a,b,< >), xmin= >, p1,...,p10), [xmin,options]=fmin(...) – [a,b]; option(1)=1 ( ( -4 ; 10 ) option(14)( 500). .

function r=m1(x) r=x^2-x-3; » xm=fmin(‘m1’,-2,3,[1, 1e-6]) Func evals x f(x) 1 -0.0901699 -2.9017 2 1.09017 -2.9017 3 1.81966 -1.5085 4 0.5 -3.25 5 0.5 -3.25 6 0.5 -3.25 xm = 0.5000

xmin=fmins(‘ fmins (‘ ’, x0,


Procedure initial golden golden parabolic parabolic parabolic

’,x0), xmin=fmins(‘ ’,x0,< >), xmin= > [], p1,...,p10), [xmin,options]=fmins(...) – : x0 – ; p1,...,p10 – ; < option(1)=1 ( -

31

), option(2)-

( 10-4), option(14)-

; 200×n).

(

function r=m2(x) r=(x(1)-1)^2+(x(2)-3)^2; » [xmin,opt]=fmins(‘m2’,[0.5 2.5]) xmin = 1.0000 3.0000 opt = 0 0.0001 0.0001 0.0000 0 72 0 0 0

(

8

0 400

0.0000 0 0.0000 0.1000

n–

(

-

, ;

). fzero(‘ ’,x0), fzero(‘ ’,x0,eps), fzero (‘ fzero (‘ ’, x0, eps, trace,p1,...,p10) – [a,b] ; trace=1 – , .

0

10

). n+1

0 0

option(3)-

-

’, x0, eps , trace),

f(a)×f(b)0,

z y0, . . z’=-m(y-y0), m>0. , , , s(z)=az+s0, d(z)= d0 - cz. y’ = k⋅(s(z)-d(z)) z’ = - m⋅ (y-y0) .

-

:

function f=odu2(t,X) y=X(1); z=X(2); a=20; c=10; s0=10; d0=50; k=0.3; m=0.1; s=a*z+s0; d= d0-c*z; y0=19; f(1)=k*(s-d) ; f(2)=-m*(y-y0); f=f'; % е о - о ец y0= 19, z0=2 » [T,Y]=ode45('odu2', [0:0.3:9],[19 2]); » [T Y] » plot(T,Y) : ans = 0 19.0000 2.0000 0.3000 20.7757 1.9731 0.6000 22.4101 1.8949 0.9000 23.7686 1.7714 1.2000 24.7427 1.6126 1.5000 25.2569 1.4313 ... ( . 8.6). Э . . ( ), ;

y=y(t), z=z(t)

: (

)

,

,

. , (

odephas2) : » opt=odeset('OutputSel',[1 2], 'OutputFcn','odephas2'); » [T,Y]=ode45('odu2', [0:0.3:9],[19 2],opt);

-

34

,

-



(

30

.8.7).

2

1.8

25

1.6 20 1.4 15 1.2 10 1 5

0

0.8

0

1

2

3

4

5

6

7

8

0.6 12

9

14

16

18

.8.6

20

22

24

26

.8.7

, “





”,

.

-

, ,

,

,

.

Э

-

-

dx1 = ( a − bx 2 )x1 − αx12 dt dx2 2 ( c dx ) x x = − + − α 1 2 2 dt









α,

t=0. ( ). function f=VolterraLog(t,x) a=4; b=2.5; c=2; d=1; alpha=0.1; f(1)= (a-b*x(2))*x(1)-alpha*x(1)^2; f(2)= (-c+d*x(1))*x(2)-alpha*x(2)^2; f=f';

-

35

» opt=odeset('OutputSel',[1 2], 'OutputFcn', 'odephas2'); » [T,X]=ode45('VolterraLog', [0 10],[3 1],opt ); 2.8 2.6 2.4

2 2.2 2 1.8 1.6

1.5

1.4 1.2 1 0.8 0.5

1

Э dx1 dt

1.5

.8.8 (α=0) 2

2.5

1 3

3.5

4

1

1.5

.8.9 (α=0.1)

2

2.5

odephas3.

3

3.5

,

3 = x 2 x3 , dt2 = − x1 x 3 , = −0.51 ⋅ x1x 2 ; dt x1 ( 0 ) = x 2 ( 0 ) = x 3 ( 0 ) = 0 :

-

:

dx

dx

function f=Eiler(t,x) f(1)= x(2)*x(3); f(2)= -x(1)*x(3) ; f(3)= -0.51*x(1)*x(2) ; f=f'; » opt=odeset('OutputSel',[1 2 3], 'OutputFcn', 'odephas3'); » [T,X]=ode45('Eiler', [0 7.25], [0 0 1], opt ); % .8.10 » [T,X]=ode45('Eiler', [0:0.25:7.25],[0 1 1]); » plot(T,X) % .8.11 1 0.8

1

0.6

0.95

0.4

0.9

0.2

0.85

0

0.8 0.75

-0.2

0.7 1

-0.4

0.5

1 0.5

0

0

-0.5

-0.5 -1

-1

P .8.10

-0.6 -0.8 -1

0

1

2

3

4

P .8.11

5

6

7

4

8

36

9. ɗɥɟɦɟɧɬɚɪɧɚɹ ɝɪɚɮɢɤɚ , Patch, Surface, Text).

-

(Axes, Line,

9.1. Ⱦɜɭɦɟɪɧɚɹ ɝɪɚɮɢɤɚ

plot (y) (

); y=y(x) ; ,

plot (x,y) = ( );

-

; plot (x,y, LineSpec) – ,

LineSpec (

)d(

)

-

: y m c r

-: -. .+*°× s(

3

)ɪ( v^(

g b w k

: ) h(

)

) -

. plot (x1,y1, LineSpec1, x1,y1, LineSpec2,...) – ( 1 2; plot (...,’PropertyName’,PropertyValue,...) – Line ( LineWidth, MarcerSize, MarcerFaceColor .) . » x=0:0.3:6; » y=besselj(0,x); % J0(x) » x1=0:0.4:8; » y1=besselj(1,x1); % J1(x) » plot(x,y,'-sk', x1,y1,'-pk','LineWidth',1 ) % .9.1

-

ɉɨɫɬɪɨɟɧɢɟ ɝɪɚɮɢɤɨɜ ɮɭɧɤɰɢɣ fplot( < >,limits) ( ) limits=[xmin,xmax]. ‘sin(x)’, ‘[sin(x) cos(x) ]’, ‘[sin(x), myfun1(x), myfun2(x)]’. -

37

limits=[xmin,xmax ymin ymax]. fplot( < >,limits, eps) c s ( 0.002) (1/eps)+1. Э (n+1 – ) LineSpec: » fplot( '[besselj(0,x) besselj(1,x) 0]',[0 10],[],20) & ezplot('f(x)') f(x), ( , ezplot('x^2-2*x+1') ), [-2π 2π] . ezplot('f(x)', limits) ezplot('f(x)', limits, fig) .

n .9.2 f(x)

1 1

0.5

0.5

0

0

-0.5

-0.5 0

1

2

3

4

5

6

7

8

0

1

2

3

4

5

.9.1

6

7

8

9

.9.2

Ƚɪɚɮɢɤ ɜ ɩɨɥɹɪɧɵɯ ɤɨɨɪɞɢɧɚɬɚɯ polar(f,r) polar(f,r, LineSpec), f– r– : x=r⋅cos(ϕ), y=r⋅sin(ϕ): » f=0:0.01:2*pi; » f=0:0.01:12*pi; » r=sin(2.*f).*cos(2.*f); » r=exp(-0.1*f); » hp=polar(f,r),hold on » hp=polar(f,r) ,hold on » set(hp,'LineWidth',4) % .9.3 » set(hp,'LineWidth',2) % 90

0.5

120

90

60

-

.9.4

1

120

0.375

60 0.8

0.25

150

0.6

30

30

150 0.4

0.125 0.2

180

0

210

330

300

240 270

180

0

210

330

240

300 270

.9.3

10

.9.4

38

Ƚɪɚɮɢɤ ɜ ɥɨɝɚɪɢɮɦɢɱɟɫɤɨɦ ɦɚɫɲɬɚɛɟ , plot,

loglog c -

,

. Ƚɪɚɮɢɤ ɜ ɩɨɥɭɥɨɝɚɪɢɮɦɢɱɟɫɤɨɦ ɦɚɫɲɬɚɛɟ semilogx semilogy c ,

plot ( ).

Ƚɪɚɮɢɤ ɫ ɞɜɭɦɹ ɨɫɹɦɢ ɨɪɞɢɧɚɬ ( ) plotyy(x1,y1,x2,y2) ‘f1’ ‘f1’,’f2’, plot, semilogx, semilogx, loglog: » x=0:0.01:12*pi; » plotyy(x,sin(x).*exp(-0.1.*x),x, 10*exp(-0.1.*x)) % .9.5

, -

1

10

0

5

-1

0

5

10

15

20

25

30

0 40

35

.9.5

9.2. Ɍɪɟɯɦɟɪɧɚɹ ɝɪɚɮɢɤɚ z=z(x,y),

:

,

,

-

. ,

plot3(x,y,z)

plot,

-

( x(i,:),y(i,:),z(i,:)

. [x,y]=meshgrid(...),

» t=0:pi/50:10*pi; » plot3(sin(t),cos(t),t) %

.9.6

.

» [x,y]=meshgrid([-2:0.1:2],[-2:0.01:2]); » z=exp(-x.^2-y.^2); » plot3(x,y,z) % .9.7

-

39

1 40

0.8

30

0.6

20

0.4 0.2

10

0 2

0 1 0.5

1 0.5

0

1

2 1

0

0

-0.5

-1

-0.5 -1

0 -1 -2

-1

.9.6

-2

.9.7

mesh(x,y,z,c), mesh(z,c), mesh(z) ( ɫ , x=1:n, y=1:m, [m,n]=size(z). » [x,y]=meshgrid(-8:0.5:8); » t=sqrt(x.^2+y.^2)+0.001; » z=sin(t)./t; » mesh(x,y,z) % .9.8

;

-

x,y

-

meshɫ , (

.9.8

meshz ).

40

» meshc(x,y,z) %

.9.9

» meshz(x,y,z)

.9.9

%

.9.10

.9.10

surf(x,y,z,c), surf(z,c), surf(z) , mesh . ,

surfɫ(...)

;

:

hidden on/off ( on); shading faceted / flat / interp ( faceted , flat – , interp –

.

9.3. Ɂɚɞɚɧɢɟ ɨɫɟɣ ɤɨɨɪɞɢɧɚɬ ,

Line >’,
, ...).

-

axec(‘< : axis([xmin xmax ymin ymax]), axis([xmin xmax ymin ymax zmin zmax]) ; axes off / on ( ) ; grid on/off , grid ( ) ; box on/off, box ( ) , ; zoom on/off ( ) ( , – ; ; zoom out .

41

9.4. Ʌɢɧɢɢ ɭɪɨɜɧɹ meshɫ (...)

surfɫ(...)

contour

: contour(X,Y,Z) -

Z =Z(X,Y),

contour(X,Y,Z,n) – ( 10), contour(X,Y,Z,v) – contour(Z), contour(Z,n), contour(Z,v) – contour(...,LineSpec) c ( . plot); [C,h]=contour (...) , ( , .). contourf(...) contourf(...) [C,h, cf]=contour (...), . » [x,y]=meshgrid(-8:0.5:8); » [x,y]=meshgrid(-2:0.25:2); » t=sqrt(x.^2+y.^2)+0.001; » t=sqrt(x.^2+y.^2)+0.001; » z=sin(t).^3./t; » z=sin(t).^3./t; » [c,h]=contour(x,y,z,20); » [c,h,cf]=contourf(x,y,z,4);

; -

, cf

8 2

6 1.5

4 1

2 0.5

0 0

-2 -0.5

-4

-1

-6

-1.5

-8 -8

-6

-4

-2

0

2

4

6

8

.9.11

-2 -2

-1.5

-1

-0.5

0

0.5

1

1.5

2

.9.12 contour3(...)

0.8

-

contour(...),

0.6

,

0.4 0.2

; [c,h]=contour3(x,y,z,20); ( .9.13).

0 -0.2 5 5

0

0 -5

-5

.9.13

42

9.5. Ⱦɨɩɨɥɧɢɬɟɥɶɧɵɟ ɜɨɡɦɨɠɧɨɫɬɢ figure ; (

-

figure(n) .

)

:

hold on/off, hold . ( ): title(‘ɬɟɤɫɬ’), title(’), title(..., ‘PropertyName’,’PropertyValue’,...), h=title(...). y=4-0.3*(x-1)

: subplot(m,n,k), subplot(mnk) – m – ,n– ,k– : » subplot(121) » plot([1:0.3:4]) » subplot(122) » plot([4:-0.3:1]) » title ('y=4-0.3(x-1)')

4

4

3.5

3.5

3

3

2.5

2.5

2

2

1.5

1.5

1

0

5

10

15

1

0

5

10

15

.9.14 : xlabel(...),

ylabel(...), zlabel(...) –

title(...).

: text(x,y,’ɬɟɤɫɬ’), text(x,y,z,’ɬɟɤɫɬ’), text(...‘PropertyName’,’PropertyValue’,...), h=text(...).) - x,y,z – . : gtext(’ɬɟɤɫɬ’), h= gtext(’ɬɟɤɫɬ’) – . legend(‘ɬɟɤɫɬ1’,‘ɬɟɤɫɬ2’,...), legend(M), legend(h,M), legend off, legend(...,pos), h= legend(...) – – ( ), off , pos ( -1 ,0– 4 , 1-4 – , [x y] – ); . » subplot(111) » t=[0:pi/30:2*pi]; » a=sin(t); b=cos(t); » x=0:60; » plot(x,a+b),hold on » hp=plot(x,a', 'g', x,b','r'); set(hp,'LineWidth',2) » legend('a+b','a=sin(t)','b=cos(t)') » title('y=sin(t)+cos(t)','FontSize',12,'FontWeight','bold')

43 y=sin(t)+cos(t) 1.5 a+b a=sin(t) b=cos(t)

1

0.5

0

-0.5

-1

-1.5

0

10

20

30

40

50

60

.9.15 , contour, contour3, contourf : clabel(C,h), clabel(C,h,v), clabel(C,h,’manual’), clabel(C), clabel(C,v), clabel(C,’manual’) – h , ’manual’ ( Return ).

9.6. ɋɩɟɰɢɚɥɶɧɚɹ ɝɪɚɮɢɤɚ ,

.

bar(y), bar(x,y) , h=bar(...) – ,

x–

y–

bar (

(

barh: ), ɭ); ,

(1 – (‘group’,’stack’) :

>1 – ,