1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Elementary mathematical and computational tools for electrical and computer engineers using Matlab - Chapter 8 pdf

56 332 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 56
Dung lượng 387,02 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

For example: • The matrix of size n ⊗ n with only the diagonal elements equal to one, otherwise zero, is P=eyen,n: For example:... • The matrix of size n ⊗ n with elements randomly chose

Trang 1

DEFINITION A matrix is a collection of numbers arranged in a

two-dimen-sional (2-D) array structure Each element of the matrix, call it M i,j, occupies

the ithrow and jthcolumn

(8.1)

We say that M is an (m ⊗ n) matrix, which means that it has m rows and n columns If m = n, we call the matrix square If m = 1, the matrix is a row vec- tor; and if n = 1, the matrix is a column vector.

8.1.1 Creating Matrices in MATLAB

8.1.1.1 Entering the Elements

In this method, the different elements of the matrix are keyed in; for example:

L

Trang 2

To find the size of the matrix (i.e., the number of rows and columns), enter:

Trang 3

ans =

8.1.1.2 Retrieving Special Matrices from the MATLAB Library

MATLAB has some commonly used specialized matrices in its library thatcan be called as needed For example:

• The matrix of size (n ⊗ n) with only the diagonal elements equal

to one, otherwise zero, is P=eye(n,n):

For example:

Trang 4

• The matrix of size (n ⊗ n) with elements randomly chosen from

the interval [0, 1], such as:

Q=rand(4,4)

gives, in one instance:

Q =

• We can select to extract the upper triangular part of the Q matrix,

but assign to all the lower triangle elements the value zero:

upQ=triu(Q)

produces

upQ =

or extract the lower triangular part of the Q matrix, but assign to all the upper

triangle elements the value zero:

Trang 5

• The single quotation mark (‘) after the name of a matrix changesthe matrix rows into becoming its columns, and vice versa, if theelements are all real If the matrix has complex numbers as ele-ments, it also takes their complex conjugate in addition to thetransposition.

• Other specialized matrices, including the whole family of sparsematrices, are also included in the MATLAB library You can find

more information about them in the help documentation.

8.1.1.3 Functional Construction of Matrices

The third method for generating matrices is to give, if it exists, an algorithmthat generates each element of the matrix For example, suppose we want to

generate the Hilbert matrix of size (n ⊗ n), where n = 4 and the functional

matrix will be as follows:

We want to expand the matrix A by the matrix B along the horizontal (this is

allowed only if both matrices have the same number of rows) Enter:

Trang 6

C =

Or, we may want to expand A by stacking it on top of B (this is allowed only

if both matrices have the same number of columns) Enter:

We illustrate the appending operations for larger matrices: define E as the

(2⊗ 3) matrix with one for all its elements, and we desire to append it

hori-zontally to D This is allowed because both have the same number of rows

Trang 7

The addition operation is the obvious one That is, the (m, n) element of the

sum (A+B) is the sum of the (m, n) elements of respectively A and B:

(8.2)Entering

(A B+ )mn =A mn+B mn

Trang 8

8.3 Multiplying a Matrix by a Scalar

If we multiply a matrix by a number, each element of the matrix is multiplied

Two matrices A(m ⊗ n) and B(r ⊗ s) can be multiplied only if n = r The size

of the product matrix is (m ⊗ s) An element of the product matrix is obtained

from those of the constitutent matrices through the following rule:

Trang 9

This result can be also interpreted by observing that the (k, l) element of the

product is the dot product of the k-row of A and the l-column of B.

In MATLAB, we denote the product of the matrices A and B by A*B.

A B

Trang 10

umn from the second matrix Of course, all three results should give the sameanswer, which they do.

8.5 Inverse of a Matrix

In this section, we assume that we are dealing with square matrices (n ⊗ n)

because these are the only class of matrices for which we can define aninverse

DEFINITION A matrix M–1 is called the inverse of matrix M if the following

conditions are satisfied:

(8.4)

(The identity matrix is the (n ⊗ n) matrix with ones on the diagonal and zero

everywhere else; the matrix eye(n,n)in MATLAB.)

EXISTENCE The existence of an inverse of a matrix hinges on the condition

that the determinant of this matrix is non-zero [det(M) in MATLAB] We leave

the proof of this theorem to future courses in linear algebra For now, the mula for generating the value of the determinant is given here

for-• The determinant of a square matrix M, of size (n ⊗ n), is a number

equal to:

(8.5)

where P is the n! permutation of the first n-integers The sign in front of each

term is positive if the number of transpositions relating

is even, while the sign is negative otherwise

Trang 11

a. If n = 2, there are only two possibilities for permuting these two

numbers, giving the following: (1, 2) and (2, 1) In the first tation, no transposition was necessary; that is, the multiplyingfactor in Eq (8.5) is 1 In the second term, one transposition isneeded; that is, the multiplying factor in Eq (8.5) is –1, giving forthe determinant the value:

permu-(8.6)

b. If n = 3, there are only six permutations for the sequence (1, 2, 3):

namely, (1, 2, 3), (2, 3, 1), and (3, 1, 2), each of which is an evenpermutation and (3, 2, 1), (2, 1, 3), and (1, 3, 2), which are oddpermutations, thereby giving for the determinant the value:

Trang 12

det(MN) = det(M) × det(N)

Prove that if the inverse of the matrix M exists, then:

8.6 Solving a System of Linear Equations

Let us assume that we have a system of n linear equations in n unknowns that

Trang 13

The above equations can be readily written in matrix notation:

(8.9)

or

where the column of b’ s and x’ s are denoted by B and X Multiplying, on the

left, both sides of this matrix equation by M–1, we find that:

As pointed out previously, remember that the condition for the existence of

solutions is a non-zero value for the determinant of M.

Example 8.3

Use MATLAB to solve the system of equations given by:

Solution: Edit and execute the following script M-file:

x x

x

b b

LL

L

MM

MM

Trang 14

Gaussian elimination technique (and its different refinements) is essentiallythe numerical method of choice for the built-in algorithms of numerical soft-wares, including MATLAB The following two examples are essential build-ing blocks in such constructions.

Example 8.4

Without using the MATLAB inverse command, solve the system of equations:

where L is a lower triangular matrix.

Solution:In matrix form, the system of equations to be solved is

(8.13)

The solution of this system can be directly obtained if we proceed iteratively

That is, we find in the following order: x1, x2, …, x n, obtaining:

(8.14)

The above solution can be implemented by executing the following script

M-file:

x

b b

LL

L

MM

MM

k kj j j k

kk

1 1 11 2

2 21 1 22

1 1

Trang 15

Solve the system of equations: UX = B, where U is an upper triangular matrix.

Solution:The matrix form of the problem becomes:

(8.15)

In this case, the solution of this system can also be directly obtained if we

pro-ceed iteratively, but this time in the backward order x n , x n–1 , …, x1, obtaining:

(8.16)

The corresponding script M-file is

x x

b b

b b

n

n

n n n n

nn n

n n

1 2 1

0

LL

Trang 16

end

x

8.7 Application of Matrix Methods

This section provides seven representative applications that illustrate theimmense power that matrix formulation and tools can provide to diverseproblems of common interest in electrical engineering

8.7.1 dc Circuit Analysis

Example 8.6

Find the voltages and currents for the circuit given in Figure 8.1

Solution:Using Kirchoff’s current and voltage laws and Ohm’s law, we canwrite the following equations for the voltages and currents in the circuit,

Trang 17

NOTE These equations can be greatly simplified if we use the method ofelimination of variables This is essentially the method of nodes analysis cov-ered in circuit theory courses At this time, our purpose is to show a directnumerical method for obtaining the solutions.

If we form column vector VI, the top three components referring to the

voltages V1, V2, V3, and the bottom three components referring to the

cur-rents I1, I2, I3, then the following script M-file provides the solution to the

Find the value of the lamp resistor in Figure 8.1, so that the current flowing

through it is given, a priori.

Solution:We approach this problem by defining a function file for the vant current In this case, it is

Trang 18

function ilamp=circuit872(RL)

M=[1 0 0 0 0 0;1 -1 0 -50 0 0;0 1 -1 0 -100 0;

0 1 0 0 0 -300;0 0 1 0 -RL 0;0 0 0 1 -1 -1]; Vs=[5;0;0;0;0;0];

Pb 8.5 For the circuit of Figure 8.1, find RL that gives a 22-mA current in the

lamp (Hint: Plot the current as function of the load resistor.)

8.7.3 ac Circuit Analysis

Conceptually, there is no difference between performing an ac steady-stateanalysis of a circuit with purely resistive elements, as was done in Subsection8.7.1, and performing the analysis for a circuit that includes capacitors andinductors, if we adopt the tool of impedance introduced in Section 6.8, and

we write the circuit equations instead with phasors The only modificationfrom an all-resistors circuit is that matrices now have complex numbers aselements, and the impedances have frequency dependence For convenience,

we illustrate again the relationships of the voltage-current phasors acrossresistors, inductors, and capacitors:

(8.17)(8.18)

(8.19)

and restate Kirchoff’s laws again:

• Kirchoff’s voltage law: The sum of all voltage drops around aclosed loop is balanced by the sum of all voltage sources aroundthe same loop

Trang 19

• Kirchoff’s current law: The algebraic sum of all currents entering(exiting) a circuit node must be zero.

In-Class Exercise

Pb 8.6 In a bridged-T filter, the voltage V s (t) is the input voltage, and the put voltage is that across the load resistor R L The circuit is given in Figure 8.3

out-Assuming that R1 = R2 = 3 Ω, R L = 2 Ω, C = 0.25 F, and L = 1 H:

a. Write the equations for the phasors of the voltages and currents

b Form the matrix representation for the equations found in part (a).

c. Plot the magnitude and phase of as a function of the frequency

d Compare the results obtained in part (c) with the analytical results

of the problem, given by:

V V

N D

Trang 20

8.7.4 Accuracy of a Truncated Taylor Series

In this subsection and subection 8.7.5, we illustrate the use of matrices as aconvenient constructional tool to state and manipulate problems with twoindices In this application, we desire to verify the accuracy of the truncatedTaylor series as an approximation to the function y = exp(x), over

the interval 0 ≤ x < 1.

Because this application’s purpose is to illustrate a constructional scheme,

we write the code lines as we are proceeding with the different tional steps:

computa-1 We start by dividing the (0, 1) interval into equally spaced ments This array is given by:

Specify the size of W, and then give the induction rule to go from

one column to the next:

(8.21)

n n

1

2 2 2 2 3

2

3 3 2 3 3

Trang 21

This is implemented in the code as follows:

LAB command sum acting on a matrix adds the column elements,

we take the sum of the adjoint (the matrix obtained, for real

ele-ments, by changing the rows to columns and vice versa) of W to

obtain our result Consequently, add to the code:

If you would also like to check the error of the approximation as a function

of x, enter:

dy=abs(y-serexp);

semilogy(x,dy)

Examining the output graph, you will find, as expected, that the error

increases with an increase in the value of x However, the approximation of

the exponential by the partial sum of the first ten elements of the truncatedTaylor series is accurate over the whole domain considered, to an accuracy ofbetter than one part per million

Question:Could you have estimated the maximum error in the above

com-puted value of dy by evaluating the first neglected term in the Taylor’s series

at x = 1?

Trang 22

In-Class Exercise

Pb 8.7 Verify the accuracy of truncating at the fifth element the followingTaylor series, in a domain that you need to specify, so the error is everywhereless than one part in 10,000:

a.

b.

c.

8.7.5 Reconstructing a Function from Its Fourier Components

From the results of Section 7.9, where we discussed the Fourier series, it is asimple matter to show that any even periodic function with period 2π can bewritten in the form of a cosine series, and that an odd periodic function can

be written in the form of a sine series of the fundamental frequency and itshigher harmonics

Knowing the coefficients of its Fourier series, we would like to plot thefunction over a period The purpose of the following example is two-fold:

1 On the mechanistic side, to illustrate again the setting up of a twoindices problem in a matrix form

2 On the mathematical contents side, examining the effects of cating a Fourier series on the resulting curve

k

= −+

.11

2

Trang 23

the function y3(x) given in Pb 8.8.

The function under consideration is given analytically by:

a. Find the value where the truncated Fourier series overshoots thevalue of 0.5 (Answer: The limiting value of this first maximum is0.58949)

b. Find the limiting value of the first local minimum (Answer: Thelimiting value of this first minimum is 0.45142)

1 1

π

Trang 24

c. Derive, from first principles, the answers to parts (a) and (b) (Hint:

Look up in a standard integral table the sine integral function.)

NOTE An important goal of filter theory is to find methods to smooth thesekinds of oscillations

8.7.6 Interpolating the Coefficients of an (n – 1)-degree Polynomial from

n Points

The problem at hand can be posed as follows:

Given the coordinates of n points: (x1, y1), (x2, y2), …, (x n , y n), we want to find

the polynomial of degree (n – 1), denoted by p n–1 (x), whose curve passes

through these points

Let us assume that the polynomial has the following form:

(8.22)

From a knowledge of the column vectors X and Y, we can formulate this

prob-lem in the standard linear system form In particular, in matrix form, we canwrite:

V(k, j) = x(k) * V(k, j – 1) (8.25)

Furthermore, the first column of V has all its elements equal to 1.

The following routine computes A:

1

2

1 1

2

2 1

1 2 1 2

a a

a

y y

L

MM

MM

A=V−1* Y

Trang 25

Find the polynomials that are defined through:

Pb 8.10 The points (1, 5), (2, 11), and (3, 19)

Pb 8.11 The points (1, 8), (2, 39), (3, 130), (4, 341), and (5, 756)

8.7.7 Least Square Fit of Data

In Section 8.7.6, we found the polynomial of degree (n – 1) that was uniquely determined by the coordinates of n points on its curve However, when data

fitting is the tool used by experimentalists to verify a theoretical prediction,many more points than the minimum are measured in order to minimize theeffects of random errors generated in the acquisition of the data But thisover-determination in the system parameters faces us with the dilemma ofwhat confidence level one gives to the accuracy of specific data points, and

which data points to accept or reject A priori, one takes all data points, and

resorts to a determination of the vector A whose corresponding polynomial

comes closest to all the experimental points Closeness is defined through theEuclidean distance between the experimental points and the predicted curve.This method for minimizing the sum of the square of the Euclidean distancebetween the optimal curve and the experimental points is referred to as theleast-square fit of the data

To have a geometrical understanding of what we are attempting to do, sider the conceptually analogous problem in 3-D of having to find the planewith the least total square distance from five given data points So what do

con-we do? Using the projection procedure derived in Chapter 7, con-we deduce eachpoint’s distance from the plane; then we go ahead and adjust the parameters

of the plane equation to obtain the smallest total square distance between thepoints and the plane In linear algebra courses, using generalized optimiza-

Trang 26

tion techniques, you will be shown that the best fit to A (i.e., the one called

least-square fit) is given (using the rotation of the previous subsection) by:

MATLAB also has a built-in command to achieve the least-square fit of data

Look up the polyfit function in your help documentation, and learn its use

and point out what difference exists between its notation and that of theabove routine

In-Class Exercise

Pb 8.12 Find the second-degree polynomials that best fit the data points: (1,8.1), (2, 24.8), (3, 52.5), (4, 88.5), (5, 135.8), and (6, 193.4)

8.8 Eigenvalues and Eigenvectors*

DEFINITION If M is a square n ⊗ n matrix, then a vector is called aneigenvector and λ, a scalar, is called an eigenvalue, if they satisfy the relation:

(8.27)that is, the vector is a scalar multiplied by the vector

v

Mv = λv

Trang 27

8.8.1 Finding the Eigenvalues of a Matrix

To find the eigenvalues, note that the above definition of eigenvectors andeigenvalues can be rewritten in the following form:

(8.28)

where I is the identity n ⊗ n matrix The above set of homogeneous equations

admits a solution only if the determinant of the matrix multiplying the vector

is zero Therefore, the eigenvalues are the roots of the polynomial p(λ),defined as follows:

(8.29)

This equation is called the characteristic equation of the matrix M It is of

degree n inλ (This last assertion can be proven by noting that the

contribu-tion to the determinant of (M – λI), coming from the product of the diagonal

elements of this matrix, contributes a factor of λn to the expression of thedeterminant.)

Example 8.9

Find the eigenvalues and the eigenvectors of the matrix M, defined as follows:

Solution:The characteristic polynomial for this matrix is given by:

The roots of this polynomial (i.e., the eigenvalues of the matrix) are,respectively,

λ1 = 1 and λ2 = 4

To find the eigenvectors corresponding to the above eigenvalues, which we

Trang 28

From the first set of equations, we deduce that: b = –a/4; and from the second set of equations that d = c/2, thus giving for the eigenvectors thefollowing expressions:

It is common to give the eigenvectors in the normalized form (that is, fix a and

values:

8.8.2 Finding the Eigenvalues and Eigenvectors Using MATLAB

Given a matrix M, the MATLAB command to find the eigenvectors and eigenvalues is given by [V,D]=eig(M); the columns of V are the eigen- vectors and D is a diagonal matrix whose elements are the eigenvalues Enter- ing the matrix M and the eigensystem commands gives:

Finding the matrices V and D is referred to as diagonalizing the matrix M It

should be noted that this is not always possible For example, the matrix isnot diagonalizable when one or more of the roots of the characteristic poly-

c d

1

1 4

0 9701

0 24254

/

Ngày đăng: 13/08/2014, 02:21

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN