![]() |
||
![]() |
Department of
Mathematics and Computer Science |
![]() |
![]() |
CS/Math 166 -- Winter, 2018
|
|
20 points DUE: noon: Monday, Feb 5, 2018 |
Solve the two linear systems listed below using some Gaussian elimination with pivoting routine.
3x + 2y - 3z + w = 5 x - y + z - w = 7 2x - 5y + 6z + 3w = 10 6x - 4y + 4z + 3w = 20System 2
x + y + z - w = 2 3x - y + z + 2w = 12 x - y + 2z + w = 9 2x + 3y + z - w = 7
You can do this using Matlab or Octove (preferred) or some other programming language (e.g., C, C++, Python).
To solve via Matlab (or Octave):
As discussed in class (lecture 8), the coefficients created via Gaussian elimination
comprise what is called an "LU" decomposition. To force a solution
of a linear system via Gaussian elimination in Matlab/Octave, one first
obtains the LU decomposition of the system matrix A. This is
done by the command
[L,U] = lu(A);To solve A*x = B, which is equivalent to L*U*x = B, one can make use of the backslash operator for "matrix division" (i.e., the linear system solver operator), and obtain x = U \ (L \ B).
If you make use of Matlab/Octave, also compute the solution directly via the backslash operator, x=A\B and see if there are any differences in the answers. (The backslash operator, when given an arbitrary matrix, checks the matrix to determine which of several solution methods is most appropriate, and may not always use Gaussian elimination.)
Although Matlab/Octave has excellent internal "error checking" in its functions, you should also explicitly check to see whether the system matrices are singular before you attempt a solution and print out a warning message. (To see if a matrix is singular using Matlab/Octave, test to see if the determinant of the matrix (det(A)) is near zero before attempting to find a solution, i.e., check to see if abs(det(A)) < 1.0e-14, for example.)
If you wish to use a programming language, you can make use of Algorithm 6.2 in the text (Burden and Faires). The code for this algorithm may be found at the on-line site for the book (see the bottom of pg x in the Preface of the text).
You should locate the appropriate "tolerance" value in the algorithm and adjust it if necessary depending on the precision of variables you are using.
An alternative Fortran solver is noted below.
Whatever way you choose to do the problem, your program should test to see if the linear system is singular and indicate an error message if necessary. (The way to do this with Matlab/Octave was noted above. If you use a different programming language, check the Gaussian elimination code to see if there is an error "flag" that returns a special value if the system matrix is singular).
NOTE: Please remember to use good programming style and plenty of comments and label the output appropriately! If you use the code that comes with the text, edit the code so that the Gaussian Elimination routine is in a separate function (subroutine) and you call it twice with different sets of values for the system matrix and the constant vector.
An alternative routine is the Fortran simq.f code from the SSP (Scientific Subroutine Library) first created in the 1960s by IBM. The source code is available at the link (with the documentation included as the initial comments). (See me for additional information about using Fortran codes.)
Turn in the source file (i.e., the program code file(s)) and the output/Matlab (or Octave) diary file. As with the previous programs, your sheets may be turned in to my office, O'Connor 7, or to my mailbox in O'Connor 31. Please staple the pages yourself and do not turn in disconnected pages!
This page is maintained by Dennis C. Smolarski, S.J.
Email: dsmolarski "at" scu.edu
Last changed: 21 October 2017.