MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar...
-
Upload
lilian-ward -
Category
Documents
-
view
227 -
download
6
Transcript of MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar...
MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
LectureLecture
77Numerical Methods for EngineeringNumerical Methods for Engineering
MECN 3500 MECN 3500
Professor: Dr. Omar E. Meza CastilloProfessor: Dr. Omar E. Meza [email protected]
http://www.bc.inter.edu/facultad/omeza
Department of Mechanical EngineeringDepartment of Mechanical Engineering
Inter American University of Puerto RicoInter American University of Puerto Rico
Bayamon CampusBayamon Campus
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
22
Tentative Lectures ScheduleTentative Lectures Schedule
TopicTopic LectureLecture
Mathematical Modeling and Engineering Problem SolvingMathematical Modeling and Engineering Problem Solving 11
Introduction to MatlabIntroduction to Matlab 22
Numerical ErrorNumerical Error 33
Root FindingRoot Finding 4-5-64-5-6
System of Linear EquationsSystem of Linear Equations 77
Least Square Curve FittingLeast Square Curve Fitting
Polynomial Interpolation Polynomial Interpolation
Numerical IntegrationNumerical Integration
Ordinary Differential Equations Ordinary Differential Equations
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Gauss EliminationGauss Elimination
Linear Algebraic EquationsLinear Algebraic Equations
33
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
To solve linear algebraic equations using To solve linear algebraic equations using the technique the technique Gauss EliminationGauss Elimination. .
44
Course ObjectivesCourse Objectives
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
An equation of the form An equation of the form ax+by+c=0 ax+by+c=0 or or equivalently equivalently ax+by=-c ax+by=-c is called a linear is called a linear equation in equation in xx and and yy variables. variables.
ax+by+cz=dax+by+cz=d is a linear equation in is a linear equation in three variables, three variables, x, yx, y, and , and zz..
Thus, a linear equation in n variables isThus, a linear equation in n variables is
aa11xx11+a+a22xx22+ … +a+ … +annxxnn = b = b A solution of such an equation consists A solution of such an equation consists
of real numbers of real numbers cc11, c, c22, c, c33, … , c, … , cnn. If you . If you need to work more than one linear need to work more than one linear equations, a system of linear equations equations, a system of linear equations must be solved simultaneously.must be solved simultaneously.
55
IntroductionIntroduction
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
For small number of equations (n For small number of equations (n ≤ 3) ≤ 3) linear equations can be solved readily linear equations can be solved readily by simple techniques such as “by simple techniques such as “method method of eliminationof elimination.”.”
Linear algebra provides the tools to Linear algebra provides the tools to solve such systems of linear equations.solve such systems of linear equations.
Nowadays, easy access to computers Nowadays, easy access to computers makes the solution of large sets of makes the solution of large sets of linear algebraic equations possible and linear algebraic equations possible and practical.practical.
66
Solving Small Number of EquationsSolving Small Number of Equations
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
There are many ways to solve a system There are many ways to solve a system of linear equations:of linear equations: Graphical methodGraphical method Cramer’s ruleCramer’s rule Method of eliminationMethod of elimination Computer methodsComputer methods..
77
Solving Small Number of EquationsSolving Small Number of Equations
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
88
The Graphical MethodThe Graphical Method
For two equations:
Solve both equations for x2:
2222121
1212111
bxaxa
bxaxa
22
21
22
212
1212
11
12
112 intercept(slope)
a
bx
a
ax
xxa
bx
a
ax
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
99
The Graphical MethodThe Graphical Method
Or equate and solve for x1
12
11
22
21
12
1
22
2
12
11
22
21
22
2
12
1
1
22
2
12
11
12
11
22
21
22
21
22
21
12
11
12
112
0
aa
aa
ab
ab
aa
aa
ab
ab
x
a
b
a
bx
a
a
a
a
a
bx
a
a
a
bx
a
ax
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
1010
The Graphical MethodThe Graphical Method
Ill-conditioned(Slopes are too close)
No solution Infinite solutions
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
1111
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
12
12
21
21
x3x3x2x
rearrange 3xx
3xx2
2x1 – x2 = 3x1 + x2 = 3
One solution
The Graphical MethodThe Graphical Method
1212
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
2x1 – x2 = 3
2x1 – x2 = – 1
No solution
The Graphical MethodThe Graphical Method
1313
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
6x1 – 3x2 = 92x1 – x2 = 3
Infinite solutions
The Graphical MethodThe Graphical Method
1414
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
2x1 – x2 = 3
2.1x1 – x2 = 3
Ill conditioned
The Graphical MethodThe Graphical Method
1515
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on Cramer’s RuleCramer’s Rule
Compute the Compute the determinant Ddeterminant D 2 x 2 matrix2 x 2 matrix
3 x 3 matrix 3 x 3 matrix 211222112221
1211 aaaaaa
aaD
3231
222113
3331
232112
3332
232211
333231
232221
131211
aa
aaa
aa
aaa
aa
aaa
aaa
aaa
aaa
D
1616
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on Cramer’s RuleCramer’s Rule
To find To find xxkk for the following system for the following system
Replace kReplace kthth column of a column of as with bs with bss (i.e., (i.e., aaikik b bi i ) )
1717
nnnnnn
nn
nn
bxaxaxa
bxaxaxa
bxaxaxa
...
...
...
2211
22222121
11212111
)
)(
ijk D(a
matrix newDx
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on Cramer’s RuleCramer’s Rule
3 x 3 matrix3 x 3 matrix
333231
232221
131211
aaa
aaa
aaa
D
33231
22221
11211
33
33331
23221
13111
22
33323
23222
13121
11
1
1
1
baa
baa
baa
DD
Dx
aba
aba
aba
DD
Dx
aab
aab
aab
DD
Dx
1818
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
1919
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on Example 9.3Example 9.3
44.05.03.01.0
67.09.15.0
01.052.03.0
321
321
321
xxx
xxx
xxx
5.03.01.0
9.115.0
152.03.0
D
8.19
44.03.01.0
67.015.0
01.052.03.01
5.29
5.044.01.0
9.167.05.0
101.03.01
9.14
5.03.044.0
9.1167.0
152.001.01
33
22
11
DD
Dx
DD
Dx
DD
Dx
2020
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Eliminate x2
Subtract to get
2222121
1212111
bxaxa
bxaxa
2122221212112
1222122211122
baxaaxaa
baxaaxaa
21122211
1212112
21121122
2121221
2121221211211122
aaaa
babax
aaaa
babax
babaxaaxaa
Elimination MethodElimination Method
Not very practical for large number (> 4) of equations
2121
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on Example 9.3Example 9.3
2 x 2 matrix2 x 2 matrix
3)1(2)2(3
)18)(1()2(3
4)1(2)2(3
)2(2)18(2
2
1
x
x
22
1823
21
21
xx
xx
2222
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
nnnnnn
n
n
b
b
b
x
x
x
aaa
aaa
aaa
2
1
2
1
21
22221
11211
The system can be written in a matrix format as
NAVIE GAUSS EliminationNAVIE GAUSS Elimination
Gauss elimination is the most important algorithm to solve systems of linear equations.
It involves by combining equations to eliminate unknowns.
It involves 2 phases:
1. Forward elimination phase: reduce the set of equations to an upper triangular system.
2. Back substitution: work from the last equation up.
2323
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
In the first step of the forward elimination phase, x1 is eliminated from all equations except the first one.
The coefficient of x1 in the first equation is called the pivot element.
The second step is to eliminate x2 from the third equation through the nth equation.
Do the same for all variables x3 to xn-1.
The goal is to set up upper triangular matrix
The back-substitution phase starts from the last equation up, to find the values of x1, x2, …, xn.
NAVIE GAUSS EliminationNAVIE GAUSS Elimination
2424
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Gauss Elimination Pseudocode
Forward elimination phase
Back substitution
NAVIE GAUSS EliminationNAVIE GAUSS Elimination
2525
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Use Gauss elimination to solve
Carry 6 significant figures.
Solution
1. Forward elimination: eliminate x1 from equation (2):
- (0.1/3)
5617.19293333.000333.7
3.193.071.0
261667.000666667.000333333.01.0
32
321
321
xx
xxx
xxx
NAVIE GAUSS Elimination
2626
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on NAVIE GAUSS Elimination
2727
Eliminate x1 from equation (3): - (0.3/3)
After eliminating x1 from equations (2) and (3), the system becomes
Eliminate x2 from equation (3):
+ (0.190000/7.00333)
After eliminating x2 from equation (3), the system becomes
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on NAVIE GAUSS Elimination
2828
2. Back Substitution: find the value of x3 from equation (3):
Substitute the value of x3 in equation (2) to find the value of x2:
Substitute the values of x2 and x3 in equation (1) to find the value of x1:
0000.70120.10
0843.703 x
50000.200333.7
)0000.7(293333.05617.19
5617.19)0000.7(293333.000333.7
2
2
x
x
00000.33
)0000.7(2.0)50000.2(1.085.7
85.7)0000.7(2.0)50000.2(1.03
1
1
x
x
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
0det AD
Pitfalls of Elimination MethodsPitfalls of Elimination Methods
Division by zero Division by zero (Partially solved by the (Partially solved by the pivoting technique) pivoting technique)
Round-off errors Round-off errors (Important when (Important when large number of equation are to be large number of equation are to be solved)solved)
Ill-conditioned systemsIll-conditioned systems: :
Small changes in coefficients result in Small changes in coefficients result in large changes in the solution.large changes in the solution.
WhenWhen
2929
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
0000.10000.10000.1
0001.20000.30003.0
21
21
xx
xx
Techniques for Improving SolutionsTechniques for Improving Solutions
Use of more significant figures Use of more significant figures (The (The simplest remedy) simplest remedy)
Pivoting Pivoting (Determine the largest (Determine the largest available coefficient in the column available coefficient in the column below the pivot element and switch below the pivot element and switch rows so that the largest element is the rows so that the largest element is the pivot element.)pivot element.)
3030
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on Techniques for Improving SolutionsTechniques for Improving Solutions
Scaling Scaling (Divide each row by the largest (Divide each row by the largest element in that row) element in that row)
2
000,100000,1002
21
21
xx
xxWithout Scaling:
With Scaling:2
100002.0
21
21
xx
xx
With Scaling and Pivoting:
100002.0
2
21
21
xx
xx
3131
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on MATLAB Script File: NGaussElim.mMATLAB Script File: NGaussElim.m
3232
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
3333
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
>>Enter Matrix A > [3 -0.1 -0.2; 0.1 7 -0.3; 0.3 -0.2 10]A = 3.0000 -0.1000 -0.2000 0.1000 7.0000 -0.3000 0.3000 -0.2000 10.0000
>>Enter Solution Vector B > [7.85 -19.3 71.4]
B = 7.8500 -19.3000 71.4000
S = 3.0000 -2.5000 7.0000
>>Enter Matrix A > [3 -0.1 -0.2; 0.1 7 -0.3; 0.3 -0.2 10]A = 3.0000 -0.1000 -0.2000 0.1000 7.0000 -0.3000 0.3000 -0.2000 10.0000
>>Enter Solution Vector B > [7.85 -19.3 71.4]
B = 7.8500 -19.3000 71.4000
S = 3.0000 -2.5000 7.0000
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on
Lecture 7Lecture 7MEC
N 3
500 I
nte
r -
Bayam
on
MEC
N 3
500 I
nte
r -
Bayam
on