Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Chau Chemometrics From Basics to Wavelet Transform

.pdf
Скачиваний:
119
Добавлен:
15.08.2013
Размер:
2.71 Mб
Скачать

appendix

269

a

m1

mk

mn

b

Figure A.8. Geometric illustration of the vectors m1 and mn obtained from the linear combination of two vectors a and b (components).

where i (i = 1, 2, . . . , k ) are called the eigenvectors of the matrix A while λi are the corresponding eigenvalues. If matrix A is a symmetric matrix, all the eigenvalues are real numbers.

If there is a nonsingular matrix , with B = A −1, the square matrices B and A are said to be similar. Also, the matrix B is called the orthogonal similar matrix of A, if is an orthogonal matrix.

Any symmetric matrix A can be transformed into a diagonal matrix through the orthogonal similar transformation of

t A = or A = t

It can be proved that the diagonal elements of are λi (i

= 1, 2, . . . , k ),

the eigenvalues of matrix A, while the column vectors i (i

= 1, 2, . . . , k )

containing the orthogonal matrix are the corresponding eigenvectors. Moreover, the rank of A is exactly equal to the number of nonzero real numbers of diagonal elements or eigenvalues of .

A.1.18. Singular-Value Decomposition

For any matrix An×m (n m), one can use the technique called singularvalue decomposition (SVD) to obtain its eigenvalues and eigenvectors. The SVD technique decomposes the matrix into three matrices as A = USVt , where U is the so-called column orthogonal matrix. This means that all columns of U are orthogonal to each other, that is, Ut U = In . S is a diagonal matrix with its diagonal elements equal to the square root of the eigenvalues of covariance matrix of A, while Vt is a row orthogonal matrix, where the column vectors of V are orthogonal to one another, or in other words, Vt V = Im . Usually in chemometrics, the matrix U is called the ‘‘scores’’ while the matrix V is called the ‘‘loadings.’’

Figure A.9 illustrates the SVD of matrix A.

270

 

 

 

appendix

 

 

 

 

=

 

 

 

 

 

 

 

A

...U

 

 

S

 

V .

 

 

 

 

 

 

 

 

 

Figure A.9. Illustration of singular value decomposition of a matrix A.

Every column in the column orthogonal matrix U is the left eigenvector of the matrix A, as

AV = US Avi = si ui

Every row in the row orthogonal matrix Vt is the right eigenvector of the matrix A because

Ut A = SVt uti A = si vit

A.1.19. Generalized Inverse

For a matrix of order (n ×m), if there is a matrix B of order (m ×n), satisfying the equation

ABA = A

then B is called a generalized inverse matrix of A and is denoted by A, or sometimes is simply called the ‘‘−’’ inverse. It can be easily seen that Ais just A−1 if matrix A is a full-rank matrix. From this point of view, it can be seen that the generalized inverse is an extension of the inverse which is only defined for square matrices. The question here is whether the generalized inverse is not unique. A unique generalized inverse can be defined by specified constraints, and such a generalized inverse is called the ‘‘+’’ inverse or the Moore--Penrose inverse, denoted as A+. It satisfies the following four conditions:

1.AA+A = A

2.A+A A+ = A+

3.(AA+)t = AA+

4.(A+A)t = A+

appendix

271

The Moore--Penrose inverse has the following features:

rank(A) = rank(A+) (A+)+ = A

(At )+ = (A+)t ((AB)+)t = (At Bt )+

It should be noted that AA+ and A+A are both symmetric and idempotent. A matrix is idempotent if the square of the matrix is equal to itself (i.e.,

A2 = A).

A.1.20. Derivative of a Matrix

If the elements in matrix A are functions of variable t, then the derivative of A is still a matrix and is denoted as d A/dt . If aij is the element at the i th row and the j th column, the element in the corresponding derivative matrix d A/dt is represented by daij /dt .

The derivative of matrix has the following properties:

 

dt

 

= dt

B +

dt

A

 

d (AB)

 

d A

 

 

d B

 

 

 

 

 

 

 

 

 

 

 

 

 

[ dt

]

= tr

dt

 

 

 

d tr(A)

 

 

 

d A

 

 

 

 

A.1.21. Derivative of a Function with Vector as Variable

Suppose that f is a number function with a vector as its variable, that is, f = f (x); the derivative of f with respect to vector x is defined as follows:

df (x)

=

df

 

df

 

 

df

 

 

df

 

t

,

,

 

, . . . ,

 

 

 

 

 

 

 

 

 

 

d x

dx1

dx2

dx3

dxn

 

Here x = [x1, x2, . . . , xn ]t . The derivative of a function of vectorial variable has the features mentioned below.

If a is constant vector, then

d (at x)

= a

 

d x

d (xt a)

= a

 

d x

d (xt Ax)

= 2Ax

 

d x

272

appendix

 

y

b

a

c

 

Figure A.10. The spectrum y of a mixture that contains three chemial components with their pure spectra a, b, and c.

Here A is a symmetric square matrix, and all the elements in matrix A are constants.

Example A.2. Suppose that the spectrum of a mixture containing three chemicals, a, b, and c (see Fig. A.10) is measured, and their pure spectra, s1, s2, and s3, are also available. Can we determine the concentrations of these three chemical compounds in the mixture? If ‘‘Yes,’’ how can we do it?

According to the Lambert--Beer law, the spectra of the mixture y are related to the concentrations of the three components by

y = c1s1 + c2s2 + c3s3 + e

Here ci (i = 1, 2, 3) are the relative concentrations of the components and vector e represents the measurement noises, which is usually assumed to be a series of random numbers with normal distribution and zero mean. Since the spectra y, s1, s2, and s3 are known, the problem now is to find the concentrations ci from the preceding equation. It can be solved in the following way.

The equation y = c1s1 + c2s2 + c3s3 + e is essentially a combination of linear equations as expressed below:

y1 = c1s11 + c2s12 + c3s13 + e1 y2 = c1s21 + c2s22 + c3s23 + e2

.

.

.

yn = c1sn1 + c2sn2 + c3sn3 + en

appendix

273

Here y = [y1, y2, . . . , yn ]t , s1 = [s11, s21, . . . , sn1]t , s2 = [s12, s22, . . . , sn2]t , and s3 = [s13, s23, . . . , sn3]t . If we express the linear equations above in matrix form and ignore the noise vector e, then we have

y = Sc

Here vector c = [c1, c2, c3]t represents the unknown relative concentrations of the three compounds and matrix S is a collection of the three spectra:

 

 

s11

s12

s13

 

 

 

 

 

 

 

 

s21

s22

s23

 

 

 

 

 

 

=

 

.

.

 

= [

 

1

2 3

]

 

.

 

 

 

 

S

 

. . .

 

 

s

 

s s

 

 

..

..

..

 

 

 

 

 

.

.

.

 

 

 

 

 

 

 

 

.

.

.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

sn1

sn2

sn3

 

 

 

 

 

In order to solve this matrix equation, we need to find the inverse of S. However, matrix S is not a square matrix, and hence no inverse matrix is available. Now, let us multiply the equation by St in the following manner:

St y = St Sc

Then it is possible to solve this equation with the help of the inverse matrix because matrix (St S) is a square matrix of full rank. In this way, the solution of the equation is expressed in the following form:

c = (St S)−1St y

Remarks

1.Note first that S is not a square matrix; thus we cannot obtain its inverse matrix directly.

2.We can prove that the solution above is essentially the famous leastsquares solution.

3.In Section A.2, the readers will see that the preceding equation can be solved easily using only one statement with the help of MATLAB.

A.2. ELEMENTARY KNOWLEDGE OF MATLAB

The major advantage of MATLAB in signal processing, especially for manipulating two-dimensional signals, is the simplicity with which signals of all types can be generated and visualized. In this section, we will show how

274

appendix

to use MATLAB to carry out vector and matrix operations. Some examples will be utilized to illustrate how simple commands can be used to produce meaningful information and plots.

For convenience, in the rest of this appendix, all the matrix and vector quantities will be shown not in the usual boldface type, as above, but in the same typeface (font) as they appear in the MATLAB command window. Readers should encounter no difficulty in determining whether a matrix or vector is used in the text.

In the MATLAB command window, one can directly give MATLAB a command to execute something. For instance, to generate a matrix of order 3 × 3, just use the following command:

>A=[1 2 3 ; 4 5 6 ; 7 8 9]

Here the two square brackets denote a matrix with the quantities enclosed, while a space is used between elements within a row and a semicolon is used for separating rows. After pressing the enter key, the following matrix will be shown in the MATLAB window:

>A =

 

 

1

2

3

4

5

6

7

8

9

To obtain the inverse of this matrix, simply key in the following command:

>B=inv(A);

The results will be stored in matrix B, which is the inverse of matrix A. The semicolon at the end of the statement is used to suppress the output appearing in the command window. This is very useful to avoid excessive outputs while running a MATLAB program.

MATLAB script is very powerful and convenient for handling matrix and vector operations. For instance, to solve the least-squares equation c=(StS)-1Sty as discussed in the previous section, just input the matrix S that contains the standard spectra and the response vector y. Then the solution can be easily obtained by the following statement:

>c=inv(S’*S)*S’*y

The symbols and ’ denote multiplication and transpose operation, respectively.

In order to further explain how to use MATLAB to do chemometric calculation, some commonly used commands will be given below.

appendix

275

A.2.1. Matrix Construction

As mentioned before, one can easily construct the matrix by directly inputting the matrix A under the MATLAB command window as follows:

>A=[1 3 5 7; 12 3 5 3; 3 5 9 1]

Then, MATLAB will store the matrix A:

A=

1

3

5

7

12

3

5

3

3

5

9

1

You can also type the following statement to produce another matrix a:

>a=[2,3,4,6;1,4,5,7]

The output matrix a will be as follows:

a=

2

3

4

6

1

4

5

7

Note that every row in matrix is separated by a semicolon.

A.2.2. Matrix Manipulation

A’: transpose of matrix A. If matrix A is a complex matrix, its transpose will be the conjugated transformation.

A+B: sum of matrices A and B. This means that the corresponding elements of matrices A and B are summed together. If A and B are scalars, the two numbers are added.

A-B: difference between matrices A and B. This means that the elements in A will be subtracted by the corresponding elements of B.

A*B: multiplication between matrices A and B. A and B can be matrices and/or vectors, if they comply with the rule of matrix multiplication.

A.*B: element-by-element multiplication between matrices A and B, that is, A(i,j)*B(i,j). Note that matrices A and B must be of the same order in this case, unless one of them is a scalar.

276

appendix

A.2.3. Basic Mathematical Functions

MATLAB provides almost all the commonly used mathematical functions. The only difference between MATLAB and other advanced computer language, such as C, Pascal, FORTRAN, and BASIC (Beginner’s All-Purpose Symbolic Instruction Code), is that variables used in MATLAB are basically all vectors and matrices. Therefore, the mathematical functions in MATLAB are operating on the elements of the matrix, for example

>A=[123 245 365 ; 345 345 232] >B=fix(0.45 A)

>C=cos(A)

These three commands will give the following results:

>A=

123 245 365

345 345 232

>B=

55 110 164

155 155 104

>C=

-0.8880 0.9990 0.8391 0.8391 0.8391 0.8880

MATLAB provides the following trigonometric functions and other commonly used functions:

sin: sine function. cos: cosine function. tan: tangent function. asin: arcsine function.

acos: arccosine function. atan: arctangent function. sinh: hyperbolic sine function. cosh: hyperbolic sine function.

tanh: hyperbolic tangent function. asinh: inverse hyperbolic sine function.

acosh: inverse hyperbolic cosine function. atanh: inverse hyperbolic tangent function.

appendix

277

abs: absolute value function. 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.

angle: phase angle function. angle(X) returns the phase angles, in radians, of a matrix with complex elements.

sqrt: square root function. sqrt(X) is the square root of the elements of X. Complex results are produced if X is not positive.

real: complex real part function. real(X) is the real part of X.

round: round toward nearest integer function. round(X) rounds the elements of X to the nearest integers.

fix: round toward zero function. fix(X) rounds the elements of X to the nearest integers toward zero.

floor: round toward minus infinity. floor(X) rounds the elements of X to the nearest integers toward minus infinity;

ceil: round toward plus infinity. ceil(X) rounds the elements of X to the nearest integers toward infinity.

sign: signum function. For each element of X, sign(X) returns 1 if the element is greater than zero, 0 if it equals zero, and −1 if it is less than zero. For complex X, sign(X)=X ./ abs(X).

rem: remainder after division. rem(x,y) is x-y.*fix(x./y) if y = 0. By convention, REM(x,0) is not a number (NaN in MATLAB). The input x and y must be real arrays of the same size, or real scalars.

gcd: greatest common divisor. G = gcd(A,B) is the greatest common divisor of corresponding elements of A and B. The arrays A and B must contain nonnegative integers and must be the same size (or either can be scalar). gcd(0,0) is 0 by convention; all other GCDs are positive integers.

lcm: least common multiple. lcm(A,B) is the least common multiple of corresponding elements of A and B. The arrays A and B must contain positive integers and must be the same size (or either can be scalar).

exp: exponential function. exp(X) is the exponential of the elements of X, e to the X. For complex Z=X+i*Y, exp(Z)= exp(X)* (cos(Y)+i*sin(Y)).

log: natural logarithm function. log(X) is the natural logarithm of the elements of X. Complex results are produced if X is not positive.

log10: common (base 10) logarithm function. log10(X) is the base 10 logarithm of the elements of X. Complex results are produced if X is not positive.

278

appendix

rat: rational approximation function. [N,D]=rat(X,tol) returns two integer matrices so that N./D is close to X in the sense that abs(N./D-X)<= tol*abs(X). The rational approximations are generated by truncating continued fraction expansions. Here tol=1.e−6 norm(X(:),1) is the default. S=rat(X) or rat(X, tol) returns the continued fraction representation as a string. The same algorithm, with the default tol, is used internally by MATLAB for format rat.

erf: error function. Y=erf(X) is the error function for each element of X. X must be real. The error function is defined as

erf(x)=2/sqrt(π) 0xexp(-t2)dt.

erfinv: inverse error function. X = erfinv(Y) is the inverse error function for each element of X. The inverse error functions satisfies y=erf(x), for −1 <= y < 1 and −∞ ≤ x ≤ ∞.

Note that all the functions mentioned above can be conveniently used for calculations. This may be one of the most convenient features of the MATLAB language.

A.2.4. Methods for Generating Vectors and Matrices

The colon operator in MATLAB is one of the most convenient tools for constructing vectors and/or matrices. For instance, with the following commands, one can easily obtain a function data table:

>x=[0.0 : 0.2 : 3.0]’; (obtaining the first column in the ans table) >y=-exp(x).* sin(x); (obtaining the second column in the ans

table)

>[x y]ans= 0 0

0.2000 -0.2427

0.4000 -0.5809

0.6000 -1.0288

0.8000 -1.5965

1.0000 -2.2874

1.2000 -3.0945

1.4000 -3.9962

1.6000 -4.9509

Соседние файлы в предмете Химия