0% found this document useful (0 votes)
27 views

Topic 4 - Solving System of Linear Algebraic Equations

The document discusses methods for solving systems of linear algebraic equations, including direct methods like Gaussian elimination and iterative methods. It provides examples of setting up and solving systems of equations using matrices and MATLAB commands like A\b and inv(A)*b.

Uploaded by

xmtqnkn8vj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Topic 4 - Solving System of Linear Algebraic Equations

The document discusses methods for solving systems of linear algebraic equations, including direct methods like Gaussian elimination and iterative methods. It provides examples of setting up and solving systems of equations using matrices and MATLAB commands like A\b and inv(A)*b.

Uploaded by

xmtqnkn8vj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Subject Tutor: Dr.

Wail Sami Sarsam


Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

Solving System of Linear Algebraic Equations


A system of algebraic equations has the form

Where the coefficients Ai j and the constants bj are known and xi represent the unknowns.
In matrix notation the equations are written as

or, simply

How we get Systems of linear algebraic equations?


Linear, algebraic equations occur in almost all branches of numerical analysis. But,
their most visible application in engineering is in the analysis of linear systems (any
system whose response is proportional to the input is deemed to be linear).
Examples:

1
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

2
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

Methods of Solution
There are two classes of methods for solving systems of linear, algebraic equations:
1. Direct methods
2. Indirect methods (iterative methods)
Direct methods
Direct methods transform the original equations into equivalent equations (equations that
have the same solution) that can be solved more easily by applying the three operations:
a) Exchanging two equations (changes sign of |A|).
b) Multiplying an equation by a nonzero constant (multiplies |A| by the same constant).
c) Multiplying an equation by a nonzero constant and then subtracting it from another
equation (leaves |A| unchanged).
Three popular direct methods are:

Upper triangular matrix Lower triangular matrix

I denotes the identity matrix

Example 1: solve the equations using gauss elimination method


4x1 − 2x2 + x3 = 11 (a)
−2x1 + 4x2 − 2x3 = −16 (b)
x1 − 2x2 + 4x3 = 17 (c)
3
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

Elimination phase
Eq. (i ) − λ × Eq. ( j) → Eq. (i )
so as to eliminate x1 from Eqs. (b) and (c):
Eq. (b) − (− 0.5) × Eq. (a) →Eq. (b)
Eq. (c) − 0.25 × Eq. (a) → Eq. (c)

After this transformation, the equations become

4x1 − 2x2 + x3 = 11 (a)


3x2 −1.5x3 = −10.5 (b)
−1.5x2 + 3.75x3 = 14.25 (c)

This completes the first pass. Now we pick (b) as the pivot equation and eliminate x2
from(c):
Eq. (c) − ( − 0.5) × Eq. (b) → Eq. (c)

which yields the equations


4x1 − 2x2 + x3 = 11 (a)
3x2 –1.5x3 = −10.5 (b)
3x3 = 9 (c)

Back substitution phase


x3 = 9/3 = 3
x2 = (−10.5 + 1.5x3)/3 = [−10.5 + 1.5(3)]/3 = −2
x1 = (11 + 2x2 − x3)/4 = [11 + 2(−2) − 3]/4 = 1

4
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

Indirect methods (Iterative Methods)


Iterative, or indirect methods, start with an initial guess of the solution x and then repeatedly
improve the solution until the change in x becomes negligible. Since the required number of
iterations can be very large, the indirect methods are, in general, slower than the direct
methods.

Example 2: Solve the equations by the Gauss–Seidel method

Solution: With the given data, the iteration formulas are

Choosing the starting values x1 = x2 = x3 = 0, we have for the first iteration

The second iteration yields

5
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

and the third iteration results in

After five more iterations the results would agree with the exact solution x1 = 3,
x2 = x3 = 1.

Solving system of linear equations using matalb


A is a matrix (the coefficients of the unknown vector x). b is a vector of the right hand side.
After rearranging the system of linear equations in the form Ax=b then there are three ways
to determine x.
1) x=A\b (matlab uses Gauss elimination algorithm).
2) x=inv(A)*b (various algorithms could be used by matlab depending on A)
3) solve or linsolve
Note: for 1 and 2 det(A) must not be zero and for x=inv(A)*b A must be square.
The determinant of a matrix is a special number that can be calculated from a square matrix.

Example 3: solve example 1 using matlab.


>> A=[4 -2 1;-2 4 -2;1 -2 4]
A=
4 -2 1
-2 4 -2
1 -2 4
>> b=[11;-16;17]
b=
11
-16
17
6
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

>> x=A\b
x=
1.0000
-2.0000
3.0000
Or
>> x=inv (A)*b
x=
1.0000
-2.0000
3.0000

Matlab could also solve overdetermined system which is the system of linear equations
where the number of unknowns is greater than the number of equations. The least-squares
solution is computed to find x=A\b instead of Gauss elimination algorithm.

Example 4

>> A=[4 -2 1 -2;-2 4 -2 1;1 -2 4 3]


A=
4 -2 1 -2
-2 4 -2 1
1 -2 4 3

>> b=[11;-16;17]
b=
11
-16
17

>> x=A\b
x=
2.2857
-3.5000
0
2.5714
7
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

Checking the results:


Left hand side and right hand side should be equaled
>> 4* 2.2857-2*( -3.5000)+0-2* 2.5714
ans =
11

>> -2* 2.2857+4*( -3.5000)+0+1* 2.5714


ans =
-16

>> 1* 2.2857-2*( -3.5000)+0+3* 2.5714


ans =
16.9999
Exercises
1. Find the determinate of the matrix A (det(A))
a) A=[1 2 3;0 0 0; 5 6 7] b) A=[1 2 3;5 6 7;0 0 0 ] c) A=[0 0 0;5 6 7;1 2 3 ]

d) A=[0 2 1;0 6 7;0 2 3 ] e) A=[1 0 3;5 0 7;9 0 3 ] f) A=[1 8 0;5 4 0;9 12 0 ]

g) A=[0 8 3;5 0 8;9 12 0 ] h) A=[0 8 3; 8 0 2;3 2 0 ] i) A=[0 -8 -3; 8 0 -2;3 2 0 ]

j) A=[1 8 0; 8 0 2;0 2 1] k) A=[1 -8 0; 8 0 -2;0 2 1] l) A=[1 2 3; 4 5 6; 7 8 9]

m) A=[1 2 3; 4 5 6; 7 8 8] n) A=[1 2 3 0; 4 5 6 5; 7 8 8 2]

2. What do you conclude from exercise 1?


When det(A)=0 ?
is the inverse of A exist when det(A)=0?

3. A=[1 2 3; 4 5 6; 7 8 8], b=[10;12;15] find x if Ax=b. solve using a) \ b) inv(A)

4. A=[1 2 3 0; 4 5 6 5; 7 8 8 2], b=[10;12;15] find x if Ax=b. solve using a) \ b) inv(A)

5. A=[1 2 3 ; 4 5 6 ; 7 8 8;2 9 1], b=[10;12;15;20] find x if Ax=b. solve using a) \ b) inv(A)


8
Subject Tutor: Dr. Wail Sami Sarsam
Numerical method lab., lec.4 3rd year class By M.Sc. Hamza A.
Mech. Eng. Department University of Baghdad

Using solve or linsolve


syms x y z
eqn1 = 2*x + y + z == 2;
eqn2 = -x + y - z == 3;
eqn3 = x + 2*y + 3*z == -10;

[A,B] = equationsToMatrix([eqn1, eqn2, eqn3], [x, y, z])

A= B=
[ 2, 1, 1 ] 2
[ -1, 1, -1 ] 3
[ 1, 2, 3 ] -10
Use linsolve to solve AX = B for the vector of unknowns X.

X = linsolve(A,B)
X=
3
1
-5
Solve the system of equations using solve.
The inputs to solve are a vector of equations,and a vector of
variables to solve the equations.
sol = solve([eqn1, eqn2, eqn3], [x, y, z ]);
Since x, y, and z are defined as syms, therefore,to display their
values, we use;

xSol = sol.x
ySol = sol.y
zSol = sol z
xSol =
3
ySol =
1
zSol =
-5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy