210 likes | 476 Views
ChE 250 Numeric Methods. Lecture #11, Chapra Chapter 9 20070209. Gauss Elimination. Background Systems of linear equations Determinates, Cramer’s Rule Calculate with Matlab/Scilab Naïve Gauss Elimination Pitfalls singularity Improving the Method Pivoting Scaling Non-linear systems
E N D
ChE 250 Numeric Methods Lecture #11, Chapra Chapter 9 20070209
Gauss Elimination • Background • Systems of linear equations • Determinates, Cramer’s Rule • Calculate with Matlab/Scilab • Naïve Gauss Elimination • Pitfalls • singularity • Improving the Method • Pivoting • Scaling • Non-linear systems • Gauss-Jordan
Linear Equations • For a set of n equations and n unknowns, the equations are said to be linear if they can be expressed as a sum of coefficients and the variable only • It is convenient to use matrix arithmetic to represent the set of equations
Linear Equations • Call the square matrix of a coefficients [A] and the column vector of variables {X} and the column vector of b coefficients {B} • To solve for the variable values given all of the constants we can multiply both sides of the equation by the inverse matrix of [A]-1
Linear Equations • The only problem with this neat solution is that generally it is difficult to calculate the inverse matrix, especially of the matrix is large • Scilab/Matlab can easily calculate inverse matrix, and will indicate if it is singular or nearly singular, but it will not detect round off error • Matlab limit?
Two Equations • For two equations and two unknowns the graphical solution is available • This can easily verify the matrix solution • Matlab is very easy to use for this type of problem
Cramer’s Rule • Cramer’s rule relies on the evaluation of the determinate of the coefficient matrix as well as that of a modified matrix • Because this is computationally intensive for large n, this method is only used for small systems
Gauss Elimination • Gauss Elimination systematically removes one variable at a time from the set until all are solved • No determinate or inverse matrix is required • This is important because calculation time is proportional to the cube of the order, n
Gauss Elimination • The idea is to eliminate one variable from all subsequent rows by subtracting a ratio of the current row • The prime indicates how many subtractions the row experienced • On the last row, that variable will be solved • Then back substitute all the way up
Pitfalls • There can be the case were two of the equations in the system are singular, they do not have a solution • The three examples below show no solution (a), infinite solution (b), and ill-conditioned (c)
Pitfalls • The matrix may contain zero values on the diagonal, which cause a ‘division by zero’ error in a program • Also the constants may be dissimilar in magnitude, which can cause round off errors in the calculations and loss of significant figures
Improving Gauss • Two techniques to reduce errors are scaling and pivoting • Pivoting • Select the largest value of aij for the current column j, i>=j and use that as the pivot • Scaling • Used with pivoting, this uses a scaled value of the row constant for comparison
Gauss with Scaled Pivots • First, scale all rows • Then decide the pivot row order • Then go back to the original matrix and perform the pivot elimination • The scaled equations also may show any singularities
Gauss with Scaled Pivots • To visualize the elimination, we can actually reorder the set to show the diagonal pivot • This step is not necessary in a computer algorithm, just follow the pivot order • Once the elimination is complete, solve for xn and then substitute this value into row n-1 and solve for xn-1, …etc. • Questions?
Gauss and Non-Linear Systems • The first step is to make a linear Taylor expansion of the equations, and use the multi-dimensional Newton-Raphson method • Using matrix notation our previous equation reduces to a linear set.
Systems of Nonlinear Equations Taylor Expansion for two variables Rearrange and group
For n equations the partials make a square matrix This can be solved using the Gauss method The problem comes up of how to calculate all those partials….frequently a finite difference method must be used Non-Linear Systems
Gauss-Jordan • Gauss-Jordan method eliminates forward and backward at every step • This produces a solution without the back substitution set which may be easier to program • However it involves approximately 50% more calculations which adds time and error to large sets
Preparation for Feb 12th • Reading • Chapra Chapter 10: LU Decomposition