= − − λ 1
( )
1 11 1 12
V a a (3.25)
and
= − − λ 1
( )
2 11 2 12
V a a (3.26)
If V is an eigenvector of a matrix A corresponding to an eigenvalue λ, then so is bV, where b is a nonzero constant [1].
MATLAB has a built-in function named eig that finds the eigenvalues of a square matrix. MATLAB’s description of the function follows:
E = EIG(X) is a vector containing the eigenvalues of a square matrix X.
[V,D] = EIG(X) produces a diagonal matrix D of eigenvalues and a full matrix V whose columns are the corresponding eigenvectors so that X*V = V*D.
For this problem, the matrix A represents X. Thus, running
[V, D] = eig(A)
gives the eigenvectors associated with λ1 and λ2. V(:,1) corresponds to λ1, and V(:,2) corresponds to λ2.
Example 3.7
Suppose in Figure 3.3 the following parameters were given:
= = = =
L1 15 mH,L2 25 mH,C1 1 F,C2 33 F We wish to create a MATLAB script that will determine
1. the eigenvalues of the system by Equations (3.21) and (3.22) by MATLAB’s eig function.
2. the eigenfunctions by both Equations (3.21) and (3.22) and MATLAB’s [V,D] output.
The program follows.
% Example_3_7.m: Eigenvalues and eigenvectors.
fprintf('Eigenvectors via MATLAB eig function:\n');
V1=V(:,1) V2=V(:,2) D
The following results were generated by MATLAB:
Eigenvalues solved via Equation 3.25: lambda1 = 68723140
6.8723 0
0 0.1176
Examining the results, it can be seen that lambda1 = D(1,1) and lambda2
= D(2,2). Also, eigenvector1 is a scalar multiple of V1 and eigenvec-tor2 is a scalar multiple of V2.
Exercises
Projects
and R3→R4→R2. You should wind up with a system of five equations and five unknowns. Solve with MATLAB using the inverse matrix technique and confirm that your answer matches the results found in Example 3.3.Project.3.2
Figure P3.2 shows a resistive circuit known as a “ladder network.”
1. Using Ohm’s law and Kirchhoff’s current law, write a system of equations for the second-order and third-order networks of Figures P3.2a and P3.2b.
In addition, write the equations for a fourth-order ladder network.
2. You should see a pattern emerging from your solutions in part 1. Use this pat-tern to write the matrix for a eighth-order ladder network. Solve for all circuit voltages using MATLAB for Vref = 5V and the following resistor values:
3. Write a MATLAB program to solve this problem automatically for arbitrary n and R0 (as shown in Figure P3.2c) under the following conditions:
Project.3.3
One very important application of the eigenvalue problem is in the theory of mechanical vibrations. Consider the system of two masses (m1 and m2 ) and three springs (with spring constants k1, k2, and k3) shown in Figure P3.3.
The governing differential equations describing the motion of the two masses are
m x1 1 =k x2( 2−x1)−k x1 1 (P3.3a)
m x2 2 = −k x2( 2−x1)−k x3 2 (P3.3b) Using MATLAB’s eig function, determine the modes of oscillation such that each mass undergoes harmonic motion at the same frequency. Use the following values:
m1 = m2 = 1500 kg, k1 = 3250 N/m, k2 = 3500 N/m, k3 =3000 N/m +–
R11
R12
R21
R22 Vref
v1 v2
(a)
+–
R11
R12
R21
R22
R31
R32
v1 v2 v3
Vref
(b)
+ –
R11
R12
R21
R22
R31
R32
Rn1
Rn2 vn v3
v1 v2
Vref
(c)
Figure P3.2 (a) Second-order resistor ladder network. (b) Third-order resistor ladder network. (c) An nth-order resistor ladder network.
Project.3.4
Suppose a manufacturer wishes to purchase a piece of equipment that costs
$40,000. He plans to borrow the money from a bank and pay off the loan in 10 years in 120 equal payments. The annual interest rate is 6%. Each month, the interest charged will be on the unpaid balance of the loan. He wishes to determine what his monthly payment will be. This problem can be solved by a system of linear equations.
Let xj be the amount in the jth payment that goes toward paying off the prin-cipal. Then, the equation describing the jth payment is
= = + −
∑
=
= −
th payment
1
M = the monthly payment P = the amount borrowed
I = the monthly interest rate = one-twelfth of the annual interest rate The total number of unknowns is 121 (120 xj values and M).
Applying Equation (P3.4a) to each month gives 120 equations. The 121st equation
1. Ask the user to enter from the keyboard the amount of the loan P, the annual interest rate I, and the time period Y (in years).
2. Set up the system of linear equations, using An m, as the coefficient matrix of the system of linear equations. The n represents the equation number, and m represents the coefficient of xm in that equation. Set x121=M.
m1 m2
Figure P3.3 Mechanical vibration problem with two degrees of freedom.
3. Solve the system of linear equations in MATLAB.
4. Print out a table consisting of four columns. The first column should be the month number, the second column the monthly payment, the third column the amount of the monthly payment that goes toward paying off the principal, and the fourth column the interest payment for that month.
Project.3.5
The tic and toc commands in MATLAB allow you to measure the execution time for a given series of commands. The tic and toc behave as a stopwatch;
tic starts the stopwatch, and toc stops it and prints the elapsed time. An exam-ple usage is
tic;
a = factorial(25);
toc;
Running this script will compute 25! and then print the total execution time:
Elapsed time is 0.005509 seconds.
Of course, the time that you see will depend on the speed of your computer.
1. Write a program in MATLAB that creates a random n × n matrix A where each element is a random integer between −Emax and Emax. Use MATLAB’s rand and round functions to accomplish this. To learn how to use these functions, type help rand and help round into the MATLAB Command window. Initially, assume that n = 100 and
=100 Emax .
2. Also, create a 1 × n column vector C with random elements, using the same values for n and Emax above.
3. Solve the equation AX.=.C for X in two ways: (a) by finding A−1 (with inv) and multiplying it by C and (b) by using Gauss elimination (the MATLAB ‘\’
operator). Use tic and toc to measure the amount of time it takes for each method. Do the results make sense?
4. Rerun your program 10 times and obtain an average execution time for the two solution methods. Also find average execution times for the following val-ues of n: 3, 10, 30, 300, 1000. Plot the execution times versus n on log-log axes.
Reference
1. Kreyszig, E., Advanced Engineering Mathematics, 8th ed., Wiley, New York, 1999.
109