Вы находитесь на странице: 1из 28

1.

MathScript 2
1.1. MathScript 2
1.2. MathScript . 3
1.3. .. 4
1.4. . 6
1.5. 7
2. MathScript . 7
2.1. ..... 7
2.1.1. ... 7
2.1.2. . 8
2.1.3. .... 9
.. 9
... 10
2.2. 18
2.3. .. 21
2.4. . 23
2.5. 26

1. MathScript
1.1. MathScript
LabVIEW 8.2 MathScript
, 500 ,
. MathScript
m-, , MATLAB.
LabVIEW m-,
Web-.
MathScript , LabVIEW.
MathScript (MathScript Window) (. 1),
MathScript (ToolsMathScript Window)
(Output Window), (Command Window), (Status)
: (Variables), (Script) (History).
, , , MathScript
. <Shift-Enter>.

(Command History), .

. 1. MathScript

MathScript ,
.
, MATLAB,
.
MathScript (MathScript Node) ,
- LabVIEW. 2 MathScript
MathScript Fundamentals, NI Example Finder.

. 2. MathScript

MathScript ,
, (Scripts & Formulas),
.

1.2. MathScript
MathScript :

advanced

approximation

audio

basic

bitwise

boolean

commands

comparison

constants

daq

dsp

geometry

libraries

linalgebra

matrix

matrixops

membership

ode

optimization

plots

polynomials

programming

sets

statistics

string

support

time

timing

trigonometric

vector

(dsp),
, , :
filter design

filter implementation

linear systems

modeling and prediction

resampling

spectral analysis

transforms

waveform generation

windows

(programming):

CaseSwitch

switch
case

[case
]
...
[otherwise
]
end

switch mode
case 'start'
a = 0;
case 'end'
a = 1;
otherwise
a = a+1;
end

For Loop

for

end

for i = 1:10
a = sin(2*pi*i/10)
end

If-Else

if

[elseif

]
...
[else
]
end

if b == 1
c=3
else
c=4
end

Range

start:[step:]end

b = 2:2:20
b 2 20.
, MathScript
, 1

While Loop

while

end

while i < 10
a = cos(2*pi*i/10)
i = i + 1;
end

1.3.
MathScript .
. , ,
. :
short 5 , 314.15927;
long 15 ,
314.159265358979326;
short e 5 , 3.14159E+2.
long e 15 ,
3.141592653589793E+2.
(), .
MathScript Preferences,
(FilePreferences).
format, support. .
MathScript .
. ,
, .
support ().
int64

64-

int32

32-

int16

16-

int8

8-

uint64

64-

uint32

32-

uint16

16-

uint8

8-

double

single

, , .
(single 4 ) (double 8 ) .
MathScript :

abs(x)

angle(x)

cart2pol(x,y,z)

()

cart2sph(x,y,z)

ceil(x)

conj(x)

cplxpair(x)

cumprod(x)

cumsum(x)

exp(x)

expm(x)

factor(x)

factorial(x)

N!

fix(x)

floor(x)

gcd(x,y)

imag(x)

lcm(x,y)

log(x)

logm(x)

log10(x)

10

log2(x)

max(x)

min(x)

mod(x,y)

nextpow2(x)

planerot(x)

pol2cart(x,y,z)

()

pow2(x)

prod(x)

real(x)

reallog(x)

realpow(x,y)

realsqrt(x)

rem(x,y)

round(x)

sign(x)

sort(x)

sortrows(x)

sph2cart(x,y,z)

sqrt(x)

sqrtm(x)

sum(x)

MathScript (trigonometric),

sin(x), cos(x)
tan(x), cot(x)

, , , ( x
)

sec(x), csc(x)

asin(x), acos(x)

(
)

atan(x), acot(x)
asec(x), acsc(x)
sinh(x), cosh(x)

tanh(x), coth(x)
sech(x), csch(x)
asinh(x), acosh(x)

atanh(x), acoth(x)
asech(x), acsch(x)
sinc(x)

sin(x)/x

atan2(x,y)

,
( )

1.4.
MathScript , .
, , .
, .
.
ASCII. .
, ,
. MathScript
. , , a=sin(3*pi/2), a , a=result, a
.
; ,
. ; .
,
ans.
ans pi , i,j ( 1 ), inf
NaN (0/0, / ..).
.
*, ,
.
MathScript , ,
. , ,
. , ,
, .
, ,
(). :
, ,
. .
.
.
.
. ,
- , ,
, . -
.
, .

[name] = Xn:dX:Xk,
name ,

, Xn, Xk
, dX ,
.

MathScript , 2
.
1.5.
MathScript .
:
function outputs=function_name(inputs)
%documentation
script

function.
outputs .
, .
function_name .
inputs , .
documentation , LabVIEW
(help).
%.
script .
.
function foo

function a = foo

function [a b] = foo

function foo()

function a = foo()

function [a b] = foo()

function foo(g)

function a = foo(g)

function [a b] = foo(g)

function foo(g, h)

function a = foo(g, h)

function [a b] = foo(g, h)

MathScript , , ,
.
, . . LabVIEW
. , foo bar, bar
foo.
. nargin
, , nargin.
,
. nargout
, .
, .
,
MathScript Preferences.
(FilePreferences). ,
.m .

2. MathScript
2.1.
.
2.1.1.

, MathScript, (Matrix).
, n m [1].
:

a11

a
A 21
...

a
n1

a12
a 22
...
an2

... a 1m

... a 2 m
= a ij .
... ...

... a nm

i a ij , j
. mn, , . n=1
-, m=1 -. n=1 m=1 .
. ,
a 11 , a 22 , a nn , , a 1n ,

a 2 n 1 , a n 1 .
, . ,
. ,

. , ,
. , .
, , .
2.1.2.


, .
- ,
. -
;. .
:
>>A=[1.1 2.5 3; 4.6 5 6]
A=
1.1
2.5
3
4.6
5
6

(matrix)
(linalgebra). ,
, .

eye

false

hadamard

hankel

hilb

invhilb

magic

ones

pascal

peaks

perms

primes

repmat

rosser

toeplitz

true

vander

wilkinson

zeros


. horzcat vertcat
.
horzcat
. horzcat(a, b, ...) [a, b, ...].
.
c = horzcat(a, b, ...)
a b .
c a b.
>>A = [1, 2; 3, 4]
B = [5, 6; 7, 8]
C = horzcat(A, B)

A=

1
3

2
4

B=

5
7

6
8

C=

1
3

2
4

5
7

6
8

vertcat horzcat, .
cat , .
cat
.

c = cat(d, a, b, ...)
d , LabVIEW , :
1. a b, : cat(1, a, b, ...) = [a; b; ...].
cat(1, a, b, ...) vertcat(a, b, ...). a b .
2. a b : cat(2, a, b, ...) = [a, b, ...].
cat(2, a, b, ...) horzcat(a, b, ...). a b .
c
>>A = [1, 2; 3, 4]
B = [5, 6; 7, 8]
C = cat(2, A, B)

A=

1
3

2
4

B=

5
7

6
8

C=

blkdiag.
blkdiag
c : c = [a, 0, , 0; 0, b, 0, ].
c = blkdiag(a, b, .)
a
b

>>A = [1, 2; 3, 4]
B = [5, 6; 7, 8]
C = blkdiag(A, B)

A=

1
3

2
4

B=

5
7

6
8

C=

1
3
0
0

2
4
0
0

0
0
5
7

0
0
6
8

2.1.3.

,
. ,
, .
, .

tril

c = tril(a)
c = tril(a, b)
a .
b a. b .
c a. b 0, c a b- . c
, a
triu tril, .
reshape

d = reshape(a, b, c)
a . a b*c.
b d. b .
c d. c .
d b c. d a,
>>A = [1, 2, 3; 4, 5, 6]
D = reshape(A, 3, 2)

A=

1
4

2
5

3
6

D=

1
4
2

5
3
6

transpose ctranspose .
transpose
.
c = transpose(a)
a .
c a. c , a
>>A = [1-i, 3+4i; 5-7i, -i]
C = transpose(A)

A=

1 - 1i
5 - 7i

3 + 4i
0 - 1i

C=

1 - 1i
3 + 4i

5 - 7i
0 - 1i

Ctranspose
- . ctranspose(a) a'
c = ctranspose(a)

a .
c - a. c , a
>>A = [1-i, 3+4i; 5-7i, -i]
C = ctranspose(A)

A=

1 - 1i
5 - 7i

3 + 4i
0 - 1i

C=

1 + 1i
3 - 4i

5 + 7i
0 + 1i

.
flipdim

c = flipdim(a, b)
a .
b , a.
b :
1.
2.
c a . c ,
>>A = [1, 2, 3, 4; 5, 6, 7, 8]
C = flipdim(A, 1)

A=

1
5

2
6

3
7

4
8

C=

5
1

6
2

7
3

8
4

fliplr , flipud .
rot90
, 90
c = rot90(a)
c = rot90(a, b)
a .
b 90 a. b
1.
c a, , b*90 . c
, a
>>A = [1, 2, 3; 4, 5, 6]
C = rot90(A)

A=

1
4

2
5

3
6

C=

3
2
1

6
5
4

circshift

c = circshift(a, b)
a .
b , . b , a
, , , .
b , a b . b .
c a
>>A = [1, 2; 3, 4; 6, 7]
B = [1, 1]
C = circshift(A, B)

A=

1
3
6

2
4
7

B=

C=

7
2
4

6
1
3

,
, (matrixops), ,
.
.

()

+
(plus())

(minus())


.
, ,

.*
(times())

.\
(ldivide())

./
(rdivide())

.^

10

(power())

(mtimes())

B. C A * B [ a ij ] * [ bik ] [ c ik ] , c ik

ij b jk

j 1

\
(mldivide())
/
(mrdivide()
)

X=A\B
A*X=B

X=A/B
X*A =B

, (.*, ./, .\, .^)


.
,
.
mpower

c = mpower(a, b)
a . b , a .
b . a , b .
a^b. c
>>A = [1+3i, 5.6; -2.3, 8-i]
B=3
C = mpower(A, B)

A=

1 + 3i
-2.3 + 0i

5.6 + 0i
8 - 1i

B=

C=

-154.8 - 82.4i
-122.18 - 29.9i

297.47 + 72.8i
269.04 - 203.88i

expm

c = expm(a)
a .
c a. c
expm1, expm2 expm3 ,
. National Instruments expm.
logm

c = logm(a)
a .
c a. c
>>E = diag([2.7183, 0.3679])
C = logm(E)

E = 2.7183 0
0
0.3679

C=

1 - 8.5562e-029i
3.6228e-015 + 1.4108e-014i

3.412e-015 + 1.3625e-014i
-0.99994 - 1.9474e-029i

, ,
, , , ,
. , ,
:
det

c = det(a)
a .
c a. c
>>A = [3, 2, -1; 1, 6, 3; 2, -4, 0]
C = det(A)

A=

3
1
2

2
6
-4

-1
3
0

C=

64

size

c = size(a)
d = size(a, dim)
[m, n] = size(a)

11

a .
dim , . dim ,
:
1. , LabVIEW .
2. , LabVIEW .
c a. c .
d dim a. d .
m n a .
>>A = [1, 4; 53, 16; 0, -81];
C = size(A)

C=

find

[i, j] = find(a)
[i, j, c] = find(a)
a .
i a. i -.
j a. j -.
c a. c -.
>>A = [1, 2, 3; 0, 0, 0; 0, 2, 3]
[I, J] = find(A)

A=

1
0

2
0

3
0

I=

1
1
3
1
3

J=

1
2
2
3
3

:
ndims ,
nnz ,
nonzeros ,
numel

.
norm

k = norm(a)
k = norm(a, type)
a .
type . type , :
1 1-norm, ;
2 ( ) 2-norm, ;
inf inf-norm, ;
'fro' ,

diag ( a

a)

, diag ( aT a )

aT a , aT a. , 'fro'.
k (type)
>>A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
C = norm(A, 'fro')

A=

1
4
7

2
5
8

3
6
9

C=

16.882

normest

k = normest(a)
k = normest(a, tol)
[k, ite] = normest(a)
[k, ite] = normest(a, tol)
a .
tol . tol .
k a. k .
ite . ite
>>A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
K1 = norm(A, 2)
K2 = normest(A)

A=

1
4
7

2
5
8

3
6
9

K1 =
K2 =

16.848
16.848

cond
,
c = cond(a)

12

c = cond(a, b)
a .
b a. b norm.
c , ( ) b.
c = ||A||p||A1||p, ||A||p .
p , p
.
2-norm
A.

>>A = [1+2i, 4i; -3-6i, -5i]
C = cond(A)

A=

1 + 2i
-3 - 6i

0 + 4i
0 - 5i

C=

5.6364

condest
1-norm
c = condest(a)
[c, d] = condest(a)
a .
c 1-norm a.
d -. d , a
>>A = [1, 2, 3; 0, 1, 1; 4, 3, 1]
= condest(A)

A=

1
0
4

2
1
3

3
1
1

23

rcond
, 1-norm
c = rcond(a)
a .
a, 1-norm. a
, c . c
>>A = [1, 2, 3; 0, 1, 1; 4, 3, 1]
D = rcond(A)

A=

1
0
4

2
1
3

3
1
1

D=

0.043478

rank
. LabVIEW ,

n = rank(a, tol)
a .
tol a. tol . tol , LabVIEW ,
: tol = max(size(a))*norm(a)*eps.
n a. n
>>B = [1, 2, 3; 4, 5, 6];
A = B'*B
rank(A)

A=

17
22
27

22
29
36

27
36
45

ans =

subspace

c = subspace(a, b)
a .
b , a.
c a b. c
a b
>>A = [1, 2, 3]'
B = [1, 1, -1]'
C = subspace(A, B)

A=

1
2
3

B=

1
1
-1

C = 1.5708

condeig
,
e = condeig(a)
[c, d, e] = condeig(a)
a .

13

c a. c , a.
d a. d .
e a
>>A = [1+2i, 4i; -3-6i, -5i]
E = condeig(A)

A=

1 + 2i
-3 - 6i

0 + 4i
0 - 5i

E=

1.4007
1.4007

eig
. eig(a)
ax = lambda*x. eig(a, b) ax = lambda*bx
ev = eig(a)
ev = eig(a, b)
[evec, evdiag] = eig(a)
[evec, evdiag] = eig(a, b)
a , .
b , a. b LabVIEW qz.
ev a a b. ev .
evec , a
a b.
evdiag , a ev
>>% Eigenvalues
A = [2, -1; 11, 4]
C = eig(A)

A=

2
11

% Compute generalized
eigenvalues and check results
B = [3, 2; -9, -1]
[EVEC, EVDIAG] = eig(A, B)

B=

3
-9

-1
4

C=

2
-1

3 + 3.1623i
3 - 3.1623i

EVEC =-0.26448 + 0.23786i


0.95926 + 0.040743i
EVDIAG =

-0.26448 - 0.23786i
0.95926 - 0.040743i

-0.7 + 0.88129i 0 + 0i
0 + 0i
-0.7 - 0.88129i

balance
.
LabVIEW balance(a) : b = t\a*t
[t, b] = balance(a)
a .
b a, , .
t
>>A = [1000, 1000; 0.001, 1];
[T, B] = balance(A)

T=

512
0

0
1

B=

1000
0.512

1.9531
1

, :
chol

c = chol(a)
a .
c a.
c c'*c = a. c , a
>>A = [23, -22, -14; -22, 144, -14; -14, -14, 35]
C = chol(A)
D = C'*C

A=

23
-22
-14

-22
144
-14

-14
-14
35

C = 4.7958 -4.5873 -2.9192


0
11.089 -2.4702
0
0
4.514

D=

23
-22
-14

-22
144
-14

-14
-14
35

cholupdate
1 . LabVIEW
, chol.
[R1, p] = cholupdate(R, x, op)
R . LabVIEW R
1 . R
.
x -. x
, R.
op 1 . op , :
'+' ( ) 1 , R'R+xx'.
'-' 1 , R'R-xx'.
R1 . R1
.
p calculation op is '-'. p 0 R1
R'R-xx'. p 0 cholupdate R1 R'R. p
1 cholupdate R'R-xx' . p 2

14

cholupdate R , .. R'R
. p 32-
>>R = rand(2)
X = rand(2, 1)
[R1, P] = cholupdate(R, X, '-')

R = 0.75444
0.50498

0.45195
0.52939

X = 0.041373
0.27944

R1 = 0.7533
0

0.43728
0.46391

P=

lu
,
l = lu(a)
[l, u] = lu(a)
[l, u, p] = lu(a)
a .
l . , [l, u, p] = lu(a), l
1 , l*u = p*a. , [l, u] = lu(a), l p'*m, m
1 . , l = lu(a), l
u . l , a.
u , l*u = p*a. u
, a.
p , l*u = p*a.
, LU- p'*a .
,
>>A = [-6, 17; 3, 8]
[L, U] = lu(A)
B = L*U

A=

-6
3

17
8

L=

1
-0.5

0
1

U=

-6
0

17
16.5

B=

-6
3

17
8

qr
QR- .
QR- a q r, pm
pv, , q*r = a*pm q*r = a(pv). LabVIEW a ,
r
r = qr(a)
[q, r] = qr(a)
[q, r] = qr(a, 0)
[q, r, pm] = qr(a)
[q, r, pv] = qr(a, 0)
a .
0 , LabVIEW QR- , , q m--min(m, n)
r min(m, n)--n, a m--n.
q QR- a.
r QR- a.
pm QR- a. pm 32- .
pv QR- a. pv - 32- .
QR- - .

>>A = rand(2)
[Q, R, P] = qr(A)

A=

0.94839
0.26431

0.85322
0.33491

Q=

-0.96329
-0.26847

-0.26847
0.96329

R = -0.98453
0

-0.91181
0.093557

P=

1
0

0
1

qz
: ax = lambda*bx.
qz q z, q'*a*z = Ha q'*b*z = Tb, Ha Tb
. (Ha, Tb) , (a, b). alpha beta
. , 0/0 1/0.
[q, z, alpha, beta, evec] = qz(a, b)
a .
eig.
b , a. b , qz(a, b)
: b^-1ax = lambda*x.
.
q , a.
z , a.
alpha . alpha , b
. bx = lambda*ax .
beta .
evec , a,
(a, b). : a*evec = b*evec*diagonal(alpha./beta).
>>A = [1, 4, -2.2; 31, 4.7, 6; 5.2, 3, -3]
B = [1, 2, 3; 4, 5, 6; 7, 8, 9]
[Q, Z, ALPHA, BETA, EVEC] = qz(A, B)

A=1
4 -2.2
31 4.7 6
5.2 3 -3

B=

1
4
7

2
5
8

3
6
9

Q=

-0.12309
-0.49237
-0.86164

-0.059291
0.87034
-0.48887

0.99062
-0.0090883
-0.13632

15

Z=

1
0
0

0
0
0.89443
-0.44721

0.44721
0.89443

ALPHA = -4.4022

-2.9885

23.858

BETA =

0.81683

10.499

EVEC = 0.32066
-0.28876
-1

-0.27985 -0.5
-0.66024
1
1
-0.5

schur
. A A = CDCH,
D , CH C
d = schur(a)
d = schur(a, option)
[c, d] = schur(a)
[c, d] = schur(a, option)
a .
option . option , :
'complex' a.
'real' a. LabVIEW
- d 1 1 2 2.
d ,
1 1 2 2. a , d
.
c , a. a , c
>>A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
[C, D] = schur(A)

A=1
4
7

2
5
8

3
6
9

C=

-0.23197
-0.52532
-0.81867

-0.88291
-0.23952
0.40387

0.40825
-0.8165
0.40825

D = 16.117
0
0

4.899
-1.1168
0

1.6063e-015
-5.5408e-016
-8.8739e-016

svd
,
- .
, ,
, 2-norm 2-norm, . svd
u v, u*s*conj(v')
sv = svd(a)
[u, s, v] = svd(a)
a m--n .
sv a. sv min(m, n).
u m--min(m, n).
s min(m, n)
.
v n--min(m, n)
>>A = [1, 2, 3, 4; 5, 6, 7, 8; 9, 0, 1, 2; 3, 4, 5, 6]
C = svd(A)

A=

1
5
9
3

2
6
0
4

3
7
1
5

4
8
2
6

C=

17.836
7.5561
0.89042
1.2864e-016

rref
,
[r, jb] = rref(a)
[r, jb] = rref(a, tol)
a .
tol . tol . 1e-16*m*n*infnorm,
m a, n a, infnorm a inf-norm. tol 0, LabVIEW
.
r a.
jb , r(1:len, jb) r--r, len = length(jb), a(:, jb)
a.
>>[R, JB] = rref([1, 2; 4, 1])

R=

1
0

0
1

JB =

hess
.
, 0
[h, t] = hess(a)
a .
h a . h , a. a
, h .
t . t , a.
h : a = t*h*t' t*t' = t'*t = eye(size(a))

16

>>A = [2, -4, 7; -1, 9, 0; -4, -7, 3]


[H, T] = hess(A)
C = T*H*T'
D = T*T'

A=

2
-1
-4

T=

C=

66.332
-34.813
64.765

2
4.1231
0

-5.8209
1.7059
1.8235

5.5783
-5.1765
10.294

-4
9
-7

7
0
3

H=

-34.813
39.927
-21.557

64.765
-21.557
-11.528

D=

1
0
0 -0.24254
0 -0.97014
69
-30.559
46.809

0
-0.97014
0.24254

-30.559
46.706
-50.176

46.809
-50.176
109.29

pinv
. A+ m--n A A+
-:
A A+ A = A;
A+ A A+ = A+;
A A+ ;
A+ A
c = pinv(a)
c = pinv(a, tol)
a .
tol . , tol, a. tol
. -1.
tol , LabVIEW , :
tol = max(m, n)*||A||*eps, A , m, n A,
||A|| 2-norm A, eps ,
1+eps>1. eps : eps = 2^(-52) = 2,22e-16.
c a. c
>>A = [1, 0, 1; 0, 0, 4]
C = pinv(A)

A=

1
0

0
0

1
4

C=

1
0
-2.6827e-017

-0.25
0
0.25

diag
. diag(a, 0) diag(a)
c = diag(a)
c = diag(a, b)
a .
b a. b .
c . c . a , diag(a)
-, a diag(a, b) -, b- a. a
n, diag(a, b) n+abs(b) b- , a
>>A = [1, 0, 0; 0, 2, 0; 0, 0, 3]
C = diag(A)

A=

1
0
0

0
2
0

0
0
3

C=

1
2
3

null
- . - A x,
, Ax = 0
c = null(a)
c = null(a, 'r')
a .
'r' .
a. c
>>A = [1, 2, 3; 4, 5, 6]
C = null(A)

A=

1
4

2
5

3
6

C=

0.40825
-0.8165
0.40825

C=

-0.38632
-0.92237

orth

c = orth(a)
a .
a. c
>>A = [1, 2, 3; 4, 5, 6]
C = orth(A)

A=

1
4

2
5

3
6

-0.92237
0.38632

polyvalm

17

c = polyvalm(a, b)
a . a .
b , a. b .
a : c = a[1]*b^n+ ... +a[n]*b+a[n+1]*I, n
a. c
>>A = [1, 1, 1]
B = [1, 2; 3, 4]
C = polyvalm(A, B)

A= 1

B=

1
3

2
4

C=

9
18

12
27

compan

c = compan(a)
a , . a
, . , n
(n-1) (n-1).
c a. c a
>>A = [1, 2, 3, 4]
C = compan(A)

A= 1

C=

-2
1
0

-3
0
1

-4
0
0

2.2.
n- :
F ( t , x , x , x ,... x ( n ) ) 0 .

x ( t ) .
n- :
x' f ( t , x , x ,... x ),
1 2
n
'1 1
x 2 f2 ( t , x1 , x 2 ,... x n ),

...
x' f ( t , x , x ,... x ).
1 2
n
n n

x1 ( t )

x2 ( t )
x ( t )
, .
...
x n ( t )

.
MathScript [2]:

ode113

ode15s

ode45

ode23

- 2-3-

ode23s


2-

ode23tb

- 2-3-

ode45

- 4-5

18

ode=(fun,times,y0 [options]),
fun - ;
times ,
y0 .
ode45.

ode45
- 45 y
[t, y] = ode45(fun, times, y0)
fun , . :
function dy = fun(t, y).
times [0 20],
, y, 1:20.
, LabVIEW , y.
, LabVIEW y, . times
, .
y0 y . y0 .
t , y. t .
y

, .
.
du
a1u cos( u * t ) , u(0)=0.1. a1 =0.5.
1.
dt
1.1. : function y = model1(t, x)
y = 0.5*x+cos(x*t);

1.2. : [t, y] = ode45(model1, [0 10], 0.1) ( );


1.3. ( ) (. 2.1).

. 2.1.
2. n- u ( n ) anu ( n 1 ) ... a2u a1u b1v MathScript
n 1
. ,
u (n-1) .
x1 u , x 2 u , ... x n u ( n 1 )

x' x 2
1

x' x 3
2

...

'
x n b1v a1 x1 a2 x 2 .... an x n .
ux
1

19

u a2u a1u 0

u ( 0 ) 0.1, u( 0 ) 0.1 a2 0.5 , a1 1 .


.
2.1. : function y=model2(t,x)
y(1)=x(2);
y(2)=0.5*x(2) x(1);
2.2. : [t, y] = ode45(model2, [0 10], [0.1, 0.1])
y, u
, : y1=y(:,1), y2=y(:,2).

(. 2.2) XY- (. 2.3).


.
(
<Ctrl>) ( Graphical First?)
.

. 2.2.

. 2.3.

,
. 2.4 ,
u a2u a1u sin( 2 * t ) .
ode45 ode23 (. 2.5).

. 2.4.

. 2.5.
ode45 ode23
3. ode15s ode23s .
n- dx / dt Bx ,
:
1. B :
(Re( k ) 0 , k 0 ,1,..., n 1 ) ;
2.

max Re( k )

min Re( k ) 0 k n 1
:

dX

dt

100
10.5
40
95

156
10
65
152

3.1. 1:

107
4
55.5
102

, , .

102
1

8
2
X ; X(0 )
.
41
1.5
1
99

20

-5.5309e+001 + 0.0000e+000i
-4.3467e+000 + 2.8169e+000i
-4.3467e+000 - 2.8169e+000i
-4.9769e-001 + 0.0000e+000i

3.2. 2: s=111,1
.
3.3. : function y=model3(t,x)
B=[100 156 107 102; -10.5 -10 -4 -8; -40 -65 -55.5 -41; -95 -152 -102 -99]
y=B*x;
: [A, B] = ode15s(model3, [0 5], [1; 2; 1.5; 1])

3.4.
2.6.

. 2.6.

2.3.
n- a ( x ) a 1 x n a 2 x n 1 ... a n x a n 1 MathScript
, a [ a ( 1 ) a ( 2 ) a ( n ) a ( n 1 )] ,
. .
, .
poly
,
. .
p = poly(z)
z . z ,
.
p , z. z , p
z. p

>>Z = [1, 2, 3, 4];
P = poly(Z)

P = 1.00000e+000

-1.00000e+001

3.50000e+001

-5.00000e+001 2.40000e+001

roots
.
c = roots(a)
a , ,
. a .
a. c
A = [5, 4, 3, 2, 1]
C = roots(A)

C=

1.3783e-001 + 6.7815e-001i
1.3783e-001 - 6.7815e-001i
-5.3783e-001 + 3.5828e-001i
-5.3783e-001 - 3.5828e-001i

polyval
. polyvalm .
c = polyval(a, b)
a . a .
b , a. b .
a : c = a[1]*b.^n+ ... +a[n]*b+a[n+1]*I, n

21

a, I , . c ,
>>A = [1, 1, 1];
B = [1, 2; 3, 4];
C = polyval(A, B)

C = 3.00000e+000
1.30000e+001

7.00000e+000
2.10000e+001

>>A = [1, 1, 1];


B = [1, 2; 3, 4];
C = polyvalm(A, B)

C=

9.00000e+000
1.80000e+001

1.20000e+001
2.70000e+00

polyint
.
c = polyint(a)
c = polyint(a, b)
a .
b . b , LabVIEW
.
c

>>A = [1, 2, 3, 4];


C = polyint(A)

C = 2.50000e-001

6.66667e-001

1.50000e+000

4.00000e+000

0.00000e+000

residue
- -
.
LabVIEW a b :
bs/as = (r1/(s-p1)) + (r2/(s-p2)) + ... + (rn/(s-pn)) + ks
s n -
, .. pj = ... = pj+m-1 , j m , -
: (rj/(s-pj)) + (rj+1/(s-pj))2 + ... + (rj+m-1/(s-pj))m.
[b, a] = residue(r, p, k)
[r2, p2, k2] = residue(b2, a2)
r - .
p - .
k a b .
b2 .
a2 .
b .
a .
r2 - .
p2 - .
k2 a2 b2
>>B = [1, 2, 3, 4];
A = [1, 1];
[R, P, K] = residue(B, A)

R = 2.00000e+000
P = -1.00000e+000
K = 1.00000e+000

1.00000e+000

2.00000e+000

polyeig
n: (a0+lambda*a1+...+lambda^n*an)*x = 0.
. .
[x, eig] = polyeig(a0, a1, ... , an)
a0 .
a1, , an , a0.
x , .
eig
>>A0 = [1, 2; 3, 4];
A1 = [2, 1; 1, 0];
A2 = [-1, -1; 0, 2];
[X, EIG] = polyeig(A0, A1, A2)
X=

EIG = 2.6590e+000 - 1.7764e-016i


-3.2948e-001 - 8.0225e-001i
-3.2948e-001 + 8.0225e-001i
5.0000e-001 + 1.4653e-017i

-9.5233e-001 + 6.6173e-002i
2.9709e-001 - 2.0643e-002i

-2.2335e-002 - 7.4473e-001i
4.1322e-001 + 5.2357e-001i

2.5345e-001 + 7.0064e-001i
1.9141e-001 - 6.3893e-001i

-7.8808e-001 - 4.4776e-002i
6.1295e-001 + 3.4826e-002i

polyfit
,
.
[p, s] = polyfit(x, y, n)
[p, s, mu] = polyfit(x, y, n)
x - .
y , y-

22

n , x y. n
x.
p . p
.
s .
mu x. LabVIEW x
. mu . mu ,

conv
.
min( p , m )

Cp

Ak B p 1 k , m A, n B. A B
k max( 1 , p 1 n )

, , .
c = conv(c1)
c = conv(c1, c2)
c1 c2 . c2 , LabVIEW c1 c1.
c c1 c2. c1 c2 , c -
, c1. c1 c2 , , LabVIEW
- .
c1 c2 , LabVIEW c1 c2 , c
, c1 c2
>>C1 = [1; 2; 3];
C2 = [3; 4];
C = conv(C1, C2)

C=

3.00000e+000
1.00000e+001
1.70000e+001
1.20000e+001

deconv
, , ,
.
[c, d] = deconv(a, b)
a b .
c a b.
d a b. LabVIEW
: a = conv(b, c)+d. c d LabVIEW a b
>>A = [3, 10, 17, 12];
B=[3 4];
[C, D] = deconv(A, B)

C = 1.00000e+000
D = 0.00000e+000

2.00000e+000
0.00000e+000

3.00000e+000
0.00000e+000

0.00000e+000

2.4.
MathScript
( , , ),
, .
.
mean

c = mean(a)
c = mean(a, b)
a .
b a, , a .
b , .
1 ( ) ;
2 .
c a. a , c a. a
, c - -
a. c
median mean
std
. .
y = std(x)
y = std(x, w)

23

x .
w . w :
1. w , , x. w 0. LabVIEW
w , w 1.
2. w , , 1. . LabVIEW
.
3. w , , 0, . .
LabVIEW .
y x. y
var ( )
std.

, -
corrcoef

r = corrcoef(x)
r = corrcoef(x, y)
[r, p, rlo, rup] = corrcoef(x, 'alpha', a, 'rows', s)
[r, p, rlo, rup] = corrcoef(x, y, 'alpha', a, 'rows', s))
x . r = corrcoef(x), x
. [r, p, rlo, rup] = corrcoef(x, 'alpha', a, 'rows', s), x . x
. x , x . x
, x ,
.
y , . x, x
. y x .
'alpha' LabVIEW, a.
a 1-a [0, 1].
0,05.
'rows' LabVIEW, s.
s NaN x. s , :
'all' ( ) .
'complete' NaN .
'pairwise' NaN i- j- x (i, j)- r.
r .
p p .
rlo rup

cov
. c = cov(x, y) c = cov(x, y, 1) cov([x(:), y(:)])
c = cov(x)
c = cov(x, option)
c = cov(x, y)
c = cov(x, y, option)
x . x
. x . x
, LabVIEW .
y , x.
option x n n-1, n x, x , x, x
. option , :
0 ( ) x n-1.
1 x n.
c . c = cov(x, y) c = cov(x, y, 1), c 2--2

xcorr
-
c = xcorr(a)
c = xcorr(a, l)
c = xcorr(a, option)
c = xcorr(a, l, option)
c = xcorr(a, b)
c = xcorr(a, b, l)
c = xcorr(a, b, option)
c = xcorr(a, b, l, option)
[c, d] = xcorr(a)
[c, d] = xcorr(a, l)
[c, d] = xcorr(a, option)
[c, d] = xcorr(a, l, option)
[c, d] = xcorr(a, b)

24

[c, d] = xcorr(a, b, l)
[c, d] = xcorr(a, b, option)
[c, d] = xcorr(a, b, l, option)
a .
b .
l -. a n, c = xcorr(a, l) 2*l+1. LabVIEW
l l n.
option , - a b. option
, .
'biased' .
'coeff' , 1, 0.
'none' ( ) .
'unbiased' .
c - a b. a , c = xcorr(a) -
a. c .
d -. l, d [-l, -l+1, ..., 0, ..., l-1, l]. d

hist
, . , LabVIEW

hist(x)
hist(x, c)
hist(x, m)
n = hist(x, c)
[n, ctr] = hist(x)
[n, ctr] = hist(x, m)
x .
c , x. c
.
m , x. m
. m 10.
n , . n .
ctr , c . ctr

histc
,
n = histc(x, edges)
[n, bin] = histc(x, edges)
x . x , histc
.
edges . edges
.
n , edges. n . n(i)
x, [edges(i), edges(i+1)]. -inf +inf
edges. n(m) x, edges(m), m edges.
bin , x. bin(k) = j , x(k)
[edges(j), edges(j+1)] j<m-1, x(k) = edges(m) j = m. bin(k) = -1, x(k)
. bin , x

rand
[0, 1]. c = rand
. c = rand(a, b) c = rand([a, b]).
c = rand
c = rand(a)
c = rand(a, b)
c = rand([a, b])
a c.
b c. a b .
c [0, 1] a--b.
b , c , a
randn rand , .
random
. random(type, a, b, c) .
random(type, a, b, c, m) random(type, a, b, c, n) m--m n--n, . random(type, a, b, c,
m, n) random(type, a, b, c, [m, n]) m--n.

25

r = random(type, a, b, c)
r = random(type, a, b, c, m)
r = random(type, a, b, c, n)
r = random(type, a, b, c, m, n)
r = random(type, a, b, c, [m, n])
type . type , :

'beta'
'bino'
'chi2'
'exp'
'f'
'gam'
'geo'
'hyge'
'logn'
'nbin'
'ncf'
'nct'
'ncx2'
'norm'
'poiss'
'rayl'
't'
'unid'
'unif'
'weib'


-

-

F-
-




F-
T-
-



T-


2
2
1
1
2
2
1
3
2
2
3
2
2
2
2
1
1
1
2
2

a, b c . m--n.
m r.
n r. m n .
r type m--n

randperm
.
c = randperm(a)
a .
c 1 a. -
detrend

y = detrend(x, option, break)
x , . x . x , LabVIEW
, .
option x. option , :
'constant' .
'linear' , break.
break x . 'constant' break
. 'linear' break .
y x

nchoosek

c = nchoosek(a, b)
a b .
c a b. c

2.5.
fminbnd

xmin = fminbnd(fun, a, b)
[xmin, fval] = fminbnd(fun, a, b)

26

fun , .
.
a b , , , . a b
.
xmin a b, fun .
fval fun , xmin. xmin fval

fminsearch
Downhill Simplex n- .

xmin = fminsearch(fun, xstart)
[xmin, fval] = fminsearch(fun, xstart)
fun , .
, xstart, .
xstart , fun. xstart
.
xmin , fun .
fval fun , xmin. xmin fval

fminunc
Quasi-Newton n- .
xmin = fminunc(fun, xstart)
[xmin, fval] = fminunc(fun, xstart
fminsearch

linprog
- , : c'*x. LabVIEW

xmin = linprog(c, aineq, bineq)
xmin = linprog(c, aineq, bineq, aeq, beq)
xmin = linprog(c, aineq, bineq, aeq, beq, min, max)
[xmin, fval] = linprog(c, aineq, bineq)
[xmin, fval] = linprog(c, aineq, bineq, aeq, beq)
[xmin, fval] = linprog(c, aineq, bineq, aeq, beq, min, max)
[xmin, fval, lambda] = linprog(c, aineq, bineq)
[xmin, fval, lambda] = linprog(c, aineq, bineq, aeq, beq)
[xmin, fval, lambda] = linprog(c, aineq, bineq, aeq, beq, min, max)
c , . c
.
aineq :
aineq*xmin <= bineq. aineq []. aineq .
bineq : aineq*xmin
<= bineq. bineq [] aineq []. bineq .
aeq : aeq*xmin =
beq. aeq can be []. aeq .
beq : aeq*xmin =
beq. beq [] aeq []. beq .
min max : min <= x <=
max. min max [].
xmin , fun .
fval fun , xmin. xmin fval
.
lambda . lambda
quadprog
, : 0.5*x'*q*x+c'*x. LabVIEW

xmin = quadprog(q, c, aineq, bineq)
xmin = quadprog(q, c, aineq, bineq, aeq, beq)
xmin = quadprog(q, c, aineq, bineq, aeq, beq, min, max)
[xmin, fval] = quadprog(q, c, aineq, bineq)
[xmin, fval] = quadprog(q, c, aineq, bineq, aeq, beq)
[xmin, fval] = quadprog(q, c, aineq, bineq, aeq, beq, min, max)
[xmin, fval, lambda] = quadprog(q, c, aineq, bineq)
[xmin, fval, lambda] = quadprog(q, c, aineq, bineq, aeq, beq)

27

[xmin, fval, lambda] = quadprog(q, c, aineq, bineq, aeq, beq, min, max)
q , . q
.

linprog
fmincon
. LabVIEW

xmin = fmincon(fun, x0, aineq, bineq)
xmin = fmincon(fun, x0, aineq, bineq, aeq, beq)
xmin = fmincon(fun, x0, aineq, bineq, aeq, beq, min, max)
xmin = fmincon(fun, x0, aineq, bineq, aeq, beq, min, max, nonlinearfun)
[xmin, fval] = fmincon(fun, x0, aineq, bineq)
[xmin, fval] = fmincon(fun, x0, aineq, bineq, aeq, beq)
[xmin, fval] = fmincon(fun, x0, aineq, bineq, aeq, beq, min, max)
[xmin, fval] = fmincon(fun, x0, aineq, bineq, aeq, beq, min, max, nonlinearfun)
[xmin, fval, lambda] = fmincon(fun, x0, aineq, bineq)
[xmin, fval, lambda] = fmincon(fun, x0, aineq, bineq, aeq, beq)
[xmin, fval, lambda] = fmincon(fun, x0, aineq, bineq, aeq, beq, min, max)
[xmin, fval, lambda] = fmincon(fun, x0, aineq, bineq, aeq, beq, min, max, nonlinearfun)
fun , . fmincon
.
x0 , fun. x0
.
nonlinearfun , , , .
, nonlinineq nonlineq. LabVIEW ,
nonlinineq <= 0 nonlineq = 0. nonlinearfun .

linprog


1.

.. MATLAB. .: -,
2005. 496 . .

2.

.. MATLAB: . , 2004. 250 .:


.

28

Вам также может понравиться