In this programming assignment, you are to compare the three Gaussian elimination based methods: LU-Decomposition without pivoting, LU-Decomposition with partial pivoting, and LU-Decomposition with complete pivoting. More precisely, write a program to read in matrices A and b and solve for x in Ax = b with all three methods and do an accuracy analysis.
You should write one internal SUBROUTINE
for each method and
no subroutines and functions should use
identifiers declared in the main program.
More precisely, name your
SUBROUTINEs as follows:
|
n <-- a positive integer <= 10, the number of rows/columns xx.xx xx.xx .... xx.xx values for row #1 xx.xx xx.xx .... xx.xx values for row #2 ................. values for other rows xx.xx xx.xx .... xx.xx values for row #n xx.xx xx.xx .... xx.xx values for matrix b
After reading in n and matrices A and b, your program should solve this system with LU-decomposition without pivoting, LU-Decomposition with partial pivot, and LU-Decomposition with complete pivoting. For LU-Decomposition, your program output should follow the pattern shown below. Replace LU-Decomposition with LU-Decomposition with Partial Pivoting for LU-Decomposition with partial pivoting, and LU-Decomposition with Complete Pivoting for LU-Decomposition with complete pivoting. The last portion marked as Pivoting Elements shows the pivot elements. This portion should be blank for LU-Decomposition without pivoting. For partial pivoting, their is no column number because only rows are swapped. For complete pivoting, since rows and columns are swapped, row numbers and column numbers must be shown.
a blank line *** LU-Decomposition *** a blank line Input Matrix A: xx.xx xx.xx .... xx.xx values of row #1 xx.xx xx.xx .... xx.xx values of row #2 ................. values of other rows xx.xx xx.xx .... xx.xx values of row #n a blank line Input Matrix b: xx.xx xx.xx .... xx.xx values of matrix b a blank line Matrix L and U After the Elimination Step: This is a single matrix with L in its lower diagonal part xx.xx xx.xx .... xx.xx values of row #1 xx.xx xx.xx .... xx.xx values of row #2 ................. values of other rows xx.xx xx.xx .... xx.xx values of row #n a blank line Matrix b After the Elimination Step: xx.xx xx.xx .... xx.xx values of the modified matrix b a blank line Number of row pivoting = XX partial and complete pivoting only a blank line Number of column pivoting = XX complete pivoting only a blank line Pivot Elements: 1: Row=XX Column=YY Value=ZZZ the location and value of max to be swapped to a1,1 2: Row=XX Column=YY Value=ZZZ the location and value of max to be swapped to a2,2 other values n-1: Row=XX Column=YY Value=ZZZ the location and value of max to be swapped to an-1,n-1 a blank line Solution Matrix x: xx.xx xx.xx .... xx.xx values of matrix x (the solution) a blank line
Finally, print the following comparison results. In this summary, each row has the solutions from different methods and their absolute errors. On each row, the first value is the xi computed with complete pivoting (Ci below), the second is the xi computed with partial pivoting (Pi below), the third is the absolute difference between Ci and Pi (i.e., |Ci-Pi|)), the fourth is the xi from LU-Decomposition without pivoting (Gi below), the fifth is the absolute difference between the LU-Decomposition result and the result with complete pivoting (i.e., |Ci-Gi|), and, finally, the sixth is the absolute difference between the LU-Decomposition result and the result with partial pivoting (i.e., |Pi-Gi|).
two blank lines *** Summary Table *** C1 P1 |C1-P1| G1 |C1-G1| |P1-G1| C2 P2 |C2-P2| G2 |C2-G2| |P2-G2| .... other values ...... Cn Pn |Cn-Pn| Gn |Cn-Gn| |Pn-Gn|
The complete output for one input should look like the following:
*** CS3911 Programming Assignment #2 *** ******* LU-Decomposition Methods ******* --- output of LU-Decomposition --- --- output of LU-Decomposition with partial pivoting --- --- output of LU-Decomposition with complete pivoting --- --- output of the summary table ---
|
The second test matrix is the so-called Pascal Matrix because it is generated from the Pascal triangle. Check the "anti"-diagonals (i.e., entries running from upper-right to lower-left). The following shows matrix A and matrix b. The solution is x1 = x2 = x3 = x4 = x5 = x6 = x7 = x8 = 10000. Click here to download this file input-2.
The third test matrix is the well-known Hilbert Matrix. In fact, it is the upper-left 5×5 portion of the infinite Hilbert matrix. The following shows matrix A and matrix b. The solution is x1 = x2 = x3 = x4 = x5 = 10000. Click here to download this file input-3. Note that the input matrices do not contain exact values of the Hilbert matrix A and matrix b, and, as a result, your solutions may be slightly different from 10000.
There are other A's and b's with known solutions in our textbook. See page 128, problems P3.36 to P3.39, and page 618 for the solutions.
This procedure may be repeated a number of times with different input files to see if your program works correctly.f90 prog2.f90 -o prog2 <-- compile your program prog2 < our-test-file <-- test your program
! ----------------------------------------------------------- ! NAME : John Smith User ID: xxxxxxxx ! DUE DATE : mm/dd/yyyy ! PROGRAM ASSIGNMENT # ! FILE NAME : xxxx.yyyy.zzzz (your unix file name) ! PROGRAM PURPOSE : ! A couple of lines describing your program briefly ! -----------------------------------------------------------
Here, User ID is the one you use to login. It is not your social security number!
For each function in your program, include a simple description like this:
! ----------------------------------------------------------- ! FUNCTION xxyyzz : (function name) ! the purpose of this function ! PARAMETER USAGE : ! a list of all parameters and their meaning ! FUNCTION CALLED : ! a list of functions that are called by this one ! -----------------------------------------------------------
You should elaborate your answer and provide details. When answering the above questions, make sure each answer starts with a new line and have the question number (e.g., Question X:) clearly shown. Separate two answers with a blank line.
Note that the file name has to be README rather than readme or Readme. Note also that there is no filename extension, which means filename such as README.TXT is NOT acceptable.
README must be a plain text file. We do not accept files produced by any word processor. Moreover, watch for very long lines. More precisely, limit the length of each line to no more than 80 characters with the Return/Enter key for line separation. Missing this file, submitting non-text file, file with long lines, or providing incorrect and/or vague answers will cost you many points. Suggestion: Use a Unix text editor to prepare your README rather than a word processor.