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

1

CHAPTER 8 SOLVING LINEAR ALGEBRAIC EQUATIONS


PROBLEMS WITH MATLAB

Linear algebraic equations can be solved ‘by hand’ using pencil and
paper, by calculator, or with software such as MATLAB. The problems
arise when we deal with more than 2 variables in the said equation.
Then, MATLAB is a software that can give us the solution.

In this chapter, we discuss some examples of using MATLAB to solve


linear algebraic equations problems.

8.1 Solution for Linear Algebraic Equation System


Consider the following general equation system:
a11x + a12 y = b1
2

a21x + a22 y = b2

Symbolic solution can be obtained by using command ‘dsolve’.

Example:
>> [x,y]=solve('a11*x+a12*y=b1, a21*x+a22*y=b2')
x=
-(-a22*b1+b2*a12)/(a11*a22-a12*a21)
y=
(a11*b2-b1*a21)/(a11*a22-a12*a21)

To clarify this answer, type


3

>> 'a11'*x+'a12'*y
ans =
-a11*(-a22*b1+b2*a12)/(a11*a22-a12*a21)+a12*(a11*b2-b1*a21)/(a11*a22-
a12*a21)

>> simplify(ans)
ans =
b1

8.2 Elimination Methods


4

This is a method to solve the system of linear equation using row


operation.

8.2.1 Row Operation

The Elimination Method consists of three elementary row operations.


1) Interchange rows
2) Multiply one row with non-zero number
3) Add a multiple of one row to a different row
5

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

A=
1 2 3
4 5 6
7 8 9

Interchange row-2 and row-3:


>> k=A(2,3); %assign value of row-2 to value k
>> A(2,:)=A(3,:); %assign value of row-3 to row-2
6

>> A(3,:)=k; %assign value k to row-3


>> A %new matrix A
A=
1 2 3
7 8 9
4 5 6

Multiply row-2 with scalar 1/7:


>> A(2,:)=(1/7)*A(2,:)
A=
1.0000 2.0000 3.0000
7

1.0000 1.1429 1.2857


4.0000 5.0000 6.0000

Row-2 + (-1) row-1:


>> A(2,:)=A(2,:)+(-1)*A(1,:)

A=
1.0000 2.0000 3.0000
0 -0.8571 -1.7143
4.0000 5.0000 6.0000
8

8.2.2 Reduced Row Echelon Form(RREF)

Method to obtain matrix of the form REF is called as Gauss Elimination


Method and the method to obtain matrix of the form RREF is called as
Gauss-Jordan Elimination Method. MATLAB use function rref to obtain
RREF.

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

4 5 6
7 8 9

>> rref(A)
ans =
1 0 -1
0 1 2
0 0 0
10

8.2.3 Reduced Row Echelon Form(RREF)- Application

A system of linear equation AX = B can be solved by reducing an


augmented matrix (A⏐B) to RREF’s form. Then the solution can be
obtained by solving system of linear equation in RREF.

Example:

>> A=[7 1 10; 3 8 5; 2 5 5];


>> B=[-1; 2; -2];
>> A_B= [A B] %augmented matrix (A|B)
11

A_B =
7 1 10 -1
3 8 5 2
2 5 5 -2

>> rref(A_B) %RREF for augmented matrix

ans =
1.0000 0 0 2.5000
0 1.0000 0 0.5000
12

0 0 1.0000 -1.9000

The RREF’s matrix above is equivalent to the system of linear equation

⎛ 1...0...0 ⎞⎛ x ⎞ ⎛ 2.5 ⎞
⎜⎜ 0...1...0 ⎟⎜
⎟⎜
y ⎟ = ⎜ 0.5 ⎟
⎟ ⎜ −1.9 ⎟
⎝ 0...0...1 ⎠⎝ ⎠ ⎝ ⎠
z

Thus the solution is: x=2.5, y=0.5 and z=-1.9.

Command to be used in MATLAB is


13

X = A_B(:,size (A_B,2))

8.3 Eigen Values and Eigen Vectors

8.4.1 Using MATLAB To Compute Eigen Values and Eigen Vectors

Example:
>> A=[1 2 1; 0 1 2; -1 3 2] %enter matrix A
A=
1 2 1
0 1 2
14

-1 3 2

>> F=poly(A) %vector F consists of characteristic polynomial


coefficient A
F=
1.0000 -4.0000 0.0000 7.0000

>> roots(F) %solve f(λ)=0

ans = %eigen values


3.3914( λ1 )
15

1.7729( λ2 )

-1.1642( λ3 )

>> lambda=ans;

Eigenvectors which are correspond to eigen values λi is solution to


homogeneous system ( λi I3 − A) x = 0. Then we use function null to obtain
eigenvectors.

Obtain eigenvector correspond to λ1=3.3914:


>> A1=lambda(1)*eye(3)-A;
16

>> v1=null(A1)
v1 =
0.6509
0.4871
0.5824

Obtain eigenvector correspond to λ2=3.3914:


>> A2=lambda(2)*eye(3)-A;
>> v2=null(A2)
v2 =
-0.9447
17

-0.3059
-0.1182

Obtain eigenvector correspond to λ3=3.3914:


>> A3=lambda(3)*eye(3)-A;
>> v3=null(A3)
v3 =
-0.2766
0.6522
-0.7058
18

The easier way to obtain eigenvalues of matrix in MATLAB is by using


function eig.

>> eig(A)
ans =
3.3914
1.7729
-1.1642

The eigenvectors which are corresponds to the above eigen values also
can obtained using function eig.
19

>> [V,D]=eig(A)

V=
0.6509 -0.9447 -0.2766
0.4871 -0.3059 0.6522
0.5824 -0.1182 -0.7058

D=
3.3914 0 0
0 1.7729 0
20

0 0 -1.1642
21

Вам также может понравиться