Final Project

Due 5:00pm, Friday, December 3, 2010 in the box in Prof. Goodwine's office.
Post Reply
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Final Project

Post by goodwine »

The Rules:
You may not consult anyone other than the instructor or the class TAs regarding this exam. If you do obtain any information about how to do this exam, inadvertently or otherwise, you must disclose it to the course instructor by email or contacting him personally. Generally, disclosing the fact you were informed about a portion of the exam will be viewed favorably, especially in the case where it was inadvertent. The purpose is to help me grade fairly.

The materials you may consult are your notes from class, the course book, the other programs you wrote for the class and the one web site listed right after this paragraph. You may not consult other web sites or google. If you have questions about the math, consult the instructor! The following web site gives a good overview of the process:

http://www.gregthatcher.com/Mathematics ... ordan.aspx

After you create the matrix on this web page, you can edit the entries. To test row-swapping, change the entries in columns 1 and 2 of the second row to be the same as the entries in the first row. This will make the 2, 2 element zero, which will require that two rows be swapped.

The Project:
This project is to write a FORTRAN77 program that uses Gauss-Jordan elimination with row pivoting to solve a system of linear algebraic equations. I decided to break the project into parts to make it more organized. You must do each part and submit a program for each part that asks you to write an F77 program. Your program will solve a system of linear algebraic equations of the form Ax=b, where A and b are given. The dimensions of A and b will also be given as part of the program and it is acceptable to hard-code into your program some assumed limits, e.g.,

Code: Select all

real A(200,200)
Your program will solve for x if there is a unique solution and provide an error message if there is not a unique solution.

What to do:
  1. First, you need to be able to generate your own matrices where you know the answer so you can test your program. Here is one way to do it. In matlab, the command

    Code: Select all

    n = 8
    A = floor(rand(n,n)*10)
    will generate a matrix of 8x8 integers between 0 and 9. Figure out how to modify the code to generate an nxn matrix with integers between -9 and +9.

    You need to check that the matrix is full rank, which is the case when Ax=b will always have a unique solution. If the determinant is not zero, then it is full rank, so in matlab type

    Code: Select all

    det(A)
    and if it's not zero, then you are good to go. You can make up a random x vector using the same procedure to generate A outlined above, or just type your own. I would recommend typing your own with some sort of pattern in it so it's easy to tell when you are getting the right answer:

    Code: Select all

    x = [1 2 3 4 5 6 7 8]'
    The single quote after the vector takes the transpose, so that the Ax is lined up properly. Then you can compute b by
    b=A*x
    So, the way the problem is given is that you are given A and b and must compute x.
  2. Your program needs to load in A and b from a data file. The data file will have n^2+n+1 numbers in it. They will all look like integers, but when you do all the row reduction stuff it result in floating point numbers, so read the data for A and b in as reals or doubles.

    The format of the data file is the very first number is an INTEGER which is n. The next n^2 numbers are A where the first n of those are the first row of A, then second n are the second row, etc. In other words, the numbers go across the rows. Your answer will be different if you read them in as columns instead of rows. In the data files I provide A is in the file in an obvious way. The last n numbers are b.

    Put the data for your made-up A and b into a data file in this format.

    The files that are provided are called dataX.d: The largest matrix size in these files is 100x100.
  3. The program I showed in the last lecture will read in the data properly. Run it on your data file to make sure it works properly. If it doesn't fix it.
  4. (20 points) Modify the program provided in the previous step to perform elementary row operations to make the first diagonal element, a(1,1), equal to 1. Then perform elementary row operations so that each of the elements under the diagonal in the first column are equal to zero. Make sure that you do the same operations on b. This is something that is each to check by hand if you print out the matrix after each step. Save this program as program1.f, print it and upload it to the course web page. I do NOT want just the final program that does everything, but each step in the process.
  5. (20 points) Copy program1.f to program2.f and modify it so that it loops through all the columns and uses elementary row operations to make the elements below the diagonal equal to zero. At this point you do not have to check the size of the element on the diagonal. If your program runs into problems, there is a small chance that is happening, so printing the size of a(i,i) before you divide the row by it may be worth doing. At this point A will be reduced to an upper triangular form with ones on the diagonal. If you are using your own A and b, then the very last element in the reduced b vector should be equal to the last element in x (explain why this is true), and if that is the case, your program is probably working correctly.
  6. (20 points) Copy program2.f to program3.f and modify it so that it loops through all the columns again and puts zeros above all the diagonal elements. After this step, A should be reduced to the identity matrix and b will be modified to be equal to x, i.e., the answer! Pivoting has not been implemented yet, so, just like above, there is a chance that your program will encounter a zero or very small diagonal element, which would cause problems.
  7. (20 points) Copy program3.f to program4.f. To deal with small diagonal elements, during the forward reduction phase (which is when you are making the elements below the diagonal zero), row shifting should be used to put the element with the largest magnitude at or below the diagonal element into the pivot position. You should use your subroutine from your previous homework to do the row shifting. So, before you make any diagonal element equal to one, you search down the column below it to find the element with the largest magnitude and switch the rows so that element is on the diagonal. Do this every time, not just when the diagonal term is small.
  8. (20 points) If the largest magnitude possible for a pivot term is less than 10E-4, i.e., the diagonal element itself and all the elements below it have a very small magnitude, a warning message should be printed that the matrix is ill-conditioned and the program should stop. This will happen mathematically when Ax=b has no solution. You can rig your own matrix to have this feature by deleting a row or column and making it an exact multiple of one of the other ones.
  9. Test your program on the data files linked above. Your final program should always use row shifting, but for debugging purposes, the first file should work without row shifting. The second file requires row shifting. I don't know what will happen with the third file. The fourth file has a matrix A and vector b for which there is no solution x, so your program should print a warning for that.
What to Submit:
The project is due at 5:00pm, Friday December 3, 2010 in my office, 365B Fitzpatrick. I will have a box to submit stuff either right outside my door or in my office. Unless you have an official excuse from the Office of Student Affairs, there will be no extensions. I am leaving for a conference that weekend and plan to grade them when traveling.
  • On each program put
    • name
    • NDID number
    • user name on this forum (so I can search for your programs if necessary).
  • Submit printouts of all the programs as well as the "answers." For the larger problems, the answers had a pattern to them, so you don't have to submit 100 numbers, just something like the answer was "[10 20 10 20 10 20...]".
  • Submit the answer for each of the data files given as well as the one for your own made-up matrix. Also upload your made-up data file so I can check it if necessary.
  • Upload all your programs (and your data file) to the course web page.
  • Document your program with comments so it is easy to grade.
Bill Goodwine, 376 Fitzpatrick
kbartlet

Re: Final Project

Post by kbartlet »

How do you get the data files linked here into data files that can be used by Fortran?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

kbartlet wrote:How do you get the data files linked here into data files that can be used by Fortran?
Save them in the same directory that your FORTRAN program runs in.
Bill Goodwine, 376 Fitzpatrick
sforde

Re: Final Project

Post by sforde »

Are you going to give us a 1,000x1,000 matrix data file, or is 100x100 the largest data file we're going to get?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

sforde wrote:Are you going to give us a 1,000x1,000 matrix data file, or is 100x100 the largest data file we're going to get?
I didn't get a chance to make the bigger ones, so 100 is the largest.
Bill Goodwine, 376 Fitzpatrick
zharris

Re: Final Project

Post by zharris »

Prof,
Do we only need to submit the outputs for the final program?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

zharris wrote:Prof,
Do we only need to submit the outputs for the final program?
Yes that's the only part that has any sort of output.
Bill Goodwine, 376 Fitzpatrick
nd13

Re: Final Project

Post by nd13 »

I copied and pasted the file that you read the matrix with, but I keep getting the same error. It reads and prints the size of the matrix, but then it gives me 'lexical error-unknown token type.' What does this mean? Could you provide me with any debugging ideas?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

nd13 wrote:I copied and pasted the file that you read the matrix with, but I keep getting the same error. It reads and prints the size of the matrix, but then it gives me 'lexical error-unknown token type.' What does this mean? Could you provide me with any debugging ideas?
I would suggest not cutting and pasting. It seems to be causing a lot of trouble for people. Right click and save it, or type it in by hand.
Bill Goodwine, 376 Fitzpatrick
sschwane

Re: Final Project

Post by sschwane »

Professor,

I can see why making one of the rows in my made up matrix the same as the other row, would cause problems, but I don't understand why making two columns the same would cause a problem. When I run my program with a matrix like this, it doesn't ever have to divide by zero. Could you explain why it is supposed to mess it up? Thanks.
sschwane

Re: Final Project

Post by sschwane »

Also, judging by the numbers, it looks like my answer for data file 2 is correct, but one of the numbers is off by .1. I printed the answers with more significant digits and found out that they are all off by very small amounts. Is this ok, or is my code making a small error?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

sschwane wrote:Also, judging by the numbers, it looks like my answer for data file 2 is correct, but one of the numbers is off by .1. I printed the answers with more significant digits and found out that they are all off by very small amounts. Is this ok, or is my code making a small error?
There are many computations that occur so there will definitely be some fluidity error. A good check would be to also run it with double precision.
Bill Goodwine, 376 Fitzpatrick
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

sschwane wrote:Professor,

I can see why making one of the rows in my made up matrix the same as the other row, would cause problems, but I don't understand why making two columns the same would cause a problem. When I run my program with a matrix like this, it doesn't ever have to divide by zero. Could you explain why it is supposed to mess it up? Thanks.
If two columns are the same then two variables are combined identically in every equation. So the two variables could be replaced by one variable that is equal to that combination. Then there would be fewer unknowns than equations.
Bill Goodwine, 376 Fitzpatrick
blee11

Re: Final Project

Post by blee11 »

When i compile the program using ifort, it runs properly, but when i run the program using pgf77, it lists errors. I found that this was because pgf77 produces an error when you tell it to add, subtract, or multiply vectors, but ifort allows this. Is it okay if i compile the program using ifort and make a comment at the top saying i used ifort
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

blee11 wrote:When i compile the program using ifort, it runs properly, but when i run the program using pgf77, it lists errors. I found that this was because pgf77 produces an error when you tell it to add, subtract, or multiply vectors, but ifort allows this. Is it okay if i compile the program using ifort and make a comment at the top saying i used ifort
You would lose some points for that since it's basically a shortcut. Probably about 15 or so total.
Bill Goodwine, 376 Fitzpatrick
edearau1

Re: Final Project

Post by edearau1 »

How do we print our program without simply "copy paste" or screenshot?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

edearau1 wrote:How do we print our program without simply "copy paste" or screenshot?
To print the program copy and paste is fine. Doing it with data files is what seems to be causing problems for people.
Bill Goodwine, 376 Fitzpatrick
pkerrian

Re: Final Project

Post by pkerrian »

Upload 1/3
Program 1
You do not have the required permissions to view the files attached to this post.
pkerrian

Re: Final Project

Post by pkerrian »

Upload 2/3
Programs 2
You do not have the required permissions to view the files attached to this post.
sschwane

Re: Final Project

Post by sschwane »

program1.f , program2.f , and program3.f

Stephen Schwaner
You do not have the required permissions to view the files attached to this post.
limhoff

Re: Final Project

Post by limhoff »

I am having problems getting my do loops to step through and change the values in the matrix, any suggestions?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

limhoff wrote:I am having problems getting my do loops to step through and change the values in the matrix, any suggestions?
At what point are you having problems? Like the first column of zeros, the lower triangular part, or what?
Bill Goodwine, 376 Fitzpatrick
astumpf

Re: Final Project

Post by astumpf »

Professor,
I'm getting errors in my third program where it's stating that my matrix functions have not been declared or that it has already been used as an external function name. Any suggestions?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

astumpf wrote:Professor,
I'm getting errors in my third program where it's stating that my matrix functions have not been declared or that it has already been used as an external function name. Any suggestions?
I can't think of anything immediately. Not that I would suggest to do this because writing functions is part of FORTRAN, but if you get totally stuck, then you can program switching rows into the main program, without a subroutine, to get it working. If you can't get it into a subroutine in a working way, you would get at least 15/20 for that program, i.e., not doing it in a subroutine would cost you 5 points at most.
Bill Goodwine, 376 Fitzpatrick
joneill5

Re: Final Project

Post by joneill5 »

Did you say that we only need to print the outputs from the final program, or do we need outputs from all 4 programs? I feel like you said this before somewhere, but I can't remember, so I wanted to make sure.
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

joneill5 wrote:Did you say that we only need to print the outputs from the final program, or do we need outputs from all 4 programs? I feel like you said this before somewhere, but I can't remember, so I wanted to make sure.
I just need the programs and "answers" where by answers I mean x. You don't need to submit 35 pages showing it doing all the row reduction stuff for any of the sections.
Bill Goodwine, 376 Fitzpatrick
joneill5

Re: Final Project

Post by joneill5 »

goodwine wrote:
joneill5 wrote:Did you say that we only need to print the outputs from the final program, or do we need outputs from all 4 programs? I feel like you said this before somewhere, but I can't remember, so I wanted to make sure.
I just need the programs and "answers" where by answers I mean x. You don't need to submit 35 pages showing it doing all the row reduction stuff for any of the sections.
But do we need the answers from all four of our programs? Like, do I have to put the resulting x from program1, program2, program3, and program4?
Or can I just print the resulting x from program4?
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Final Project

Post by goodwine »

joneill5 wrote:
goodwine wrote:
joneill5 wrote:Did you say that we only need to print the outputs from the final program, or do we need outputs from all 4 programs? I feel like you said this before somewhere, but I can't remember, so I wanted to make sure.
I just need the programs and "answers" where by answers I mean x. You don't need to submit 35 pages showing it doing all the row reduction stuff for any of the sections.
But do we need the answers from all four of our programs? Like, do I have to put the resulting x from program1, program2, program3, and program4?
Or can I just print the resulting x from program4?
Submit all the programs. Also submit what you compute for x for the programs that are supposed to compute it.
Bill Goodwine, 376 Fitzpatrick
mtrembla

Re: Final Project

Post by mtrembla »

Final Project Uploads 2
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “AME 20214, Final Project”