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

SCILAB:

1.
:

-
?
?
?
?
?
?
() ?
?
?
(-) ?

,

. Scilab
, ,
.
( ) ,
.
, ,
.
,
.

singularity

()

determinant

identity matrix

absolute value, magnitude

matrix norm

inverse of matrix

pseudoinverse

pensil matrix

dimension

rank of a matrix

sparse matrix

eigenvalues of matrices

singular value decomposition (SVD)

(-) kernel, nullspace

(inverse of matrix)?
1.
inv.

inv(X)

X : ,
.
, invr.
inv(X)*X, (
=1, =0).
LU-, LAPACK.
1.
a=[1 2 3;2 2 3; 5 -1 2]
b=inv(a)

:
b =
! - 1.
1.
! - 1.5714286
1.8571429
!
1.7142857 - 1.5714286

-8.327E-17 !
- .4285714 !
.2857143 !

c=a*b

:
c =
!
1.
0.
! - 8.882E-16
1.
!
4.441E-16 - 8.882E-16

1.110E-16 !
0.
!
1.
!

.
2.
, (
).
r=[poly([1 2 3],"x","c"),1;poly([1 -2],"x","c"),2]

:
r =
! 1 + 2x + 3x2
!
! 1 - 2x

1 !
!
2 !

inv(r)

:
ans =
!
2
! -----------! 1 + 6x + 6x2
!
! - 1 + 2x
! -----------! 1 + 6x + 6x2

- 1
!
--------------- !
1 + 6x + 6x2
!
!
1 + 2x + 3x2
!
--------------- !
1 + 6x + 6x2
!

: (singular)
( ) (, a=[1 2 3;11 22 33; 110
220 330]), b=inv(a) :
!--error 19
singular matrix

2.
invr.

F = invr(H)

H :
F :
F=H-1
(Leverrier).
3.
coffg.

Fs : .
coffg Fs-1 - (co-factors method).
,
:
Ns = ( ) d = .
, Fs, Ns/d.
3

: .
.
r=[poly([1 2 3],"x","c"),1;poly([1 -2],"x","c"),2]
r =
!1 + 2x + 3x2
1!
!
!
!1 - 2x
2!
[a,d]=coffg(r)

:
d =
1 + 6x + 6x2
a =
! 2
- 1
!
!
!
!- 1 + 2x
1 + 2x + 3x2 !
, s=a/d r.

(pseudoinverse) ?
pinv.

pinv(A,[tol])

A :
tol :
X , A',
:
A*X*A = A, X*A*X = X A*X X*A (Hermitian) .
SVD (Singular Value
Decomposition) , (tolerance)
. pinv.
.
A=rand(5,2)*rand(2,4);
norm(A*pinv(A)*A-A,1) //

norm ,
.

?
svd (=singular value decomposition).

s=svd(X)
[U,S,V]=svd(X)
[U,S,V]=svd(X,0) (obsolete)
4

[U,S,V]=svd(X,"e")
[U,S,V,rk]=svd(X [,tol])

X :
s : ( )
S : ( )
U, V : ( ).
tol : . .
svd (X, S V), :
S , X.
;
U V : X = U*S*V'
" ".
X m n m > n, n
U, S n n.
s=svd(X), s, .
[U,S,V,rk]=svd(X [,tol]) rk,
X, ,
tol.
tol .
.
X=rand(4,2)*rand(2,4)
svd(X)
sqrt(spec(X*X'))

?
spec.
help spec.

?
norm.
. ,
,
" ".
.
.
norm.
[y]=norm(x [,flag])

x : ( full sparse)
flag : ( ) ( =2)

:
norm(x) : norm(x,2) x
(max(svd(x))).
norm(x,1) : , maxi(sum(abs(x),'r'))).
norm(x,'inf'),norm(x,%inf) : (infinity norm) x.
: maxi(sum((x),'c')).
norm(x,'fro') : (Frobenius).
sqrt(sum(diag(x'*x))).
p-.
norm(v,p) : l_p (sum(v(i)p))(1/p) .
norm(v) : =norm(v,2), p=2.
norm(v,'inf') : max(abs(v(i))).
:
p=1, 2, infinity.
norm(v,1) .
norm(v,1)=|x(1)|+|x(2)|+...+|x(n)|
norm(v,2)
norm(v,2)=(|x(1)|2+|x(2)|2+...+|x(n)|2)1/2
norm(v,'inf')
.
v=[1,2,3];
norm(v,1) // : 6=1+2+3
norm(v,'inf') // : =3
A=[1,2;3,4]
norm(A,1) // =6.
(2+4)

?
abs.

t=abs(x)

x :
t :
x.
x , abs(x)
x.
1.
a=[1.1

-2.2

3;4.4

-5.4

0]

:
a=
! 1.1 - 2.2
! 4.4 - 5.4
t=abs(a)

3. !
0. !

:
! 1.1
! 4.4

2.2
5.4

3. !
0. !

2.
x=[1,%i,2;-1,-%i,1+%i] //%i -

:
x =
!
1.
i
! - 1. - i
t=abs(x)

2.
!
1. + i !

:
ans =
! 1.
! 1.

1.
1.

2.
!
1.4142136 !

() ?
1.
det.
: .
det
det(X) [e,m]=det(X)

X : ,

m : , 10.
e : ,

.
det(X)= m*10e
det(X) determ(X).
det(X) detr(X).
1.
x=poly(0,'x');
a=[x,1+x;2-x,5]

:
a=
!x
!
!2 - x

1 + x!
!
5
!

D=det(a)

:
D =- 2 + 4x^2 + x

2.
s=[1,2.3;-4,5.2]
[e,m]=det(s)
D=det(s)

:
D=14.4
m = 1.44
e = 1.

, det(s)=m*10e.
2.
detr.

d=detr(h)

h :
(Leverrier).
3.
determ(X).
( ) .
, ,
.

res=determ(W [,k])

W :
k : , W
.
FFT.
.
s=poly(0,'s');
w=[s, 1+s^2;s-2, s+4]
w =
!
s
!
! - 2 + s

1 + s2 !
!
4 + s!

determ(w)

:
ans =
2 + 3s + 3s2 - s3
determ(w,2)

:
ans =
5 + 2s

: determ k ,
det(w).

?
diag.

[y]=diag(vm, [k])

vm : ( )
k : . "0",
diag(vm) diag(vm,0) .
y :
vm diag(vm,k) ,
k - . diag(vm)
diag(vm,0). k>0
, , k<0 .
.
A=[1,2;3,4]
A =
! 1. 2. !
! 3. 4. !
d_1=diag(A) //

:
d_1 =
! 1. !
! 4. !
diag(A,1)

: ans =2
diag(A,-1)

: ans =4
: sysdiag.

?
rank.

[i]=rank(X)
[i]=rank(X,tol)

X :
tol :
:
.

. .
tol .

.
a=[1 2 3; -6 3 -2;10 20 30;49 -2 5]

:
a =
!
!
!
!

1.
-6.
10.
49.

2.
3.
20.
-2.

3.
-2.
30.
5.

!
!
!
!

t=rank(a)

:
t =
3.

(-) ?
kernel.
(-) :
,
.
.
A AW=0.
kernel
W=kernel(A [,tol,[,flag])

A : . ,
( sparse), A.
flag : , 'svd' ( ) 'qr'
tol :
W :
kernel - A.
W=kernel(A) A. W ,
:
A*W=0 .
flag tol : flag = 'qr' 'svd' (
'svd'). .
tol = . tol
%eps(~2.220E-16).
.
A=[2 -3 5 7;4 -6 2 3;2 -3 -11 -15]
A
!
!
!

=
2. - 3.
5.
7. !
4. - 6.
2.
3. !
2. - 3. - 11. - 15. !

W=kernel(A)

10

W =
!
.3026009
!
.2244353
! - .7491452
!
.5448329 -

.7751569
.5075518
.3042427
.2212674

!
!
!
!

s=A*W

:
s =
1.0E-14 *
! .0444089 .0222045 !
! .0666134 .0666134 !
! .1776357 .0888178 !

, s .


linsolve.

[x0,kerA]=linsolve(A,b [,x0])

A : na x ma
"" (sparse).
b :, A ( na
x0 :
kerA : ma x k
linsolve A*x+b=0.
x0 ( ) kerA A. x=x0+kerA*w
c w, A*x+b=0.
.
:
x1-x2+1=0
-2*x1-x2+3=0
a=[1 -1;-2 -1]
b=[1 3]'
[x,kerA]=linsolve(a,b)

:
x =
! .6666667 !
! 1.6666667 !

:
r=a*x+b

11

:
r =
1.0E-15 *
! .3330669 !
! .4440892 !

:
"" kerA=[]. A
, linsolve kerA.
A ( Scilab) ,
:
WARNING:Conflicting linear constraints!
kerA =
[]
x =
[]

12