**Symbolic Linear Algebra**

You can perform operations with symbolic matrices in much the same way as .with numeric matrices. Here we give examples of finding matrix products, the matrix inverse, eigenvalues, and the characteristic polynomial of a matrix Remember that using symbolic matrices avoids numerical imprecision in subsequent operations. You can create a symbolic matrix from a numeric matrix in several ways, as shown in the following session:

»A = sym([3, 5; 2, 7]); % the most direct method

»B = [3, 5; 2, 7];

»C = sym(S);%B is preserved as a numeric matrix

»D = subs (A, t 3, 5; 2, 7]);

The first method is the most direct. Use the second method when you want to keep a numeric version of the matrix. The matrices A and C are symbolic and identical. The matrices Band Dlook like A and C but are numeric of class double. You can create a symbolic matrix consisting of functions. For example, the relationship between the coordinates (X2. Y2) of a coordinate system rotated

counterclockwise through an angle a relative to the (x l s YI) coodinate system is

X2 = XI cosa +YI sina

Y2 = YI cosa – XI sina

These equations can be expressed in matrix form as

The symbolic matrix R.can be defined in MATLAB as follows:

»syrns a

»R = [cos(a), sin(a); -sin(a), cos(a) 1

R

cos (a),

-sin (a),

sin(a) 1

cos(a) 1

If we rotate the coordinate system twice by the same angle to produce a third coordinate system (X3, Y3), the result is the same as a single rotation with twice the angle. Let us see if MATLAB gives that result. The vector-matrix equation is = R = RR

Thus R(a)R(a) should be the same as R(2a). Continue the previous session as

follows:

»Q = R*R

Q

cos(a)A2-sin(a)A2, 2*cos(a)*sin(a)

[ -2*cos(a)*sin(a), cos(a)A2-sin(a)A2

»Q = sirnple(Q)

Q =

cos(2*a), sin(2*a)

-sin(2*a), cos(2*a)

The matrix Q is the same as R(2a), as we suspected. To evaluate a matrix numerically, use the subs and double functions. For example, for a rotation of a = 1r/4 rad (45°),

»R = subs(R,a,p

**Characteristic polynom1 and Roots**

Sets of first-order differential equations can be expressed in vector-matrix notation as

10.6 Symbolic Linear Algebra 633 x=Ax+Bf(t)

whereX is the vector of dependent variables and r(t) is a vectorccntaining the forcing functions. For example, the equation set

XI = X2

X2 = -kxl – 2X2 + f(t)

comes from the equation of motion of a mass connected to a spring and sliding on a surface having viscous friction. The term f(t) is the applied force acting on the mass. For this set the vector x and the matrices A and B are

B = The equation 151- AI = 0 is the characteristic equation of the model.where 5 represents the characteristic roots of the model. Use the poly (A)function to find this polynomial, and note that MATLAB uses the default symbolic variable x to represent the roots. For example, to find the characteristic equation and solve

for the roots in terms of the spring constant k, use the following session:

»syms k

»A = [0 ,1i-k, -z r •

»poly(A)

ans =

x”2+2*x+k

»solve(ans)

ans

[ -1+(1-k)”(1/2)

[ -1- (l-k) A (1/2)

Thus the roots are 5 = -1 ± .;r-=k.

Use the eig (A) function to find the roots directly without finding the char-‘ acteristic equation (eig stands for “eigenvalue,” which is another term for “characteristic

root”). For example,

»syms k

»A = [0 ,1i-k, -2]i

»eig(A)

ans =

-1+(1-k)”(1/2)

-1- (l-k)” (1/2) 1

You can use the inv (A) and det; (A) functions to invert and find the tenninant of a matrix symbolically. For example, using the same matrix A the previous session,

>::>inv(A)

ans =

[-2/k, -11k J

[ I, a J

»A*ans % verify that the inverse is correct

ans =

[ I, a

[. a I 1

»det(A)

ans =

k

**Solving Linear Algebraic Equations**

You can use matrix methods in M~TLAB to solve linear algebraic equa•.••.a•• sym . By. You can use the matrix inverse method, if the inverse exis t-division method (see Chapter 6 for a discussion of these methods .

example, to solve the set

2x – 3y = 3

5x +cy = 19

using both methods, the session is

»syms c

»A = sym( [2, -3; 5, cJ);

»b = sym( [3; 19J);

»x = inv(A)*b % the matrix inverse method

x =

[3*c/(2*c+15)+57/(?*c+15)J

[231 (2*c+15) J

»x = A\b % the left-division method

. x =

[3*(19+c)/(2*c+15)J

[231 (2-*c+15) J

.Although the results appear to be different, they both reduce to the same sol

x = 3(19 + c)/(2c + 15), y = 23/(2c + 15).

Table 10.6-1 summarizes the functions used in this section. Note that

**Test Your Understanding**

110.6-1 Consider three successive coordinate rotations using the same angle a. Show that the product RRR of the rotation matrix R(a) given by (10.6-1) equals R(3a).

110.6-2 Find the characteristic polynomial and roots of the following matrix.

A = (Answers: s2 +7s + 10+ 3k and s = (-7 ± ../9 – 12k)/2.)

110.6-3 Use the matrix inverse and the left-division method to solve the following

set.

-:-4x +6y = -2c

7x -4y = 23

(Answer: x = (69 – 4c)/13, y = (46 – 7c)/13.)