Homework 8, due November 18.

Due Thursday, November 18, 2010.
Post Reply
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Homework 8, due November 18.

Post by goodwine »

Collaborative Problem: Write a program with a subroutine called switchrows that will switch two rows in a matrix. If the matrix is called A, then switchrows(A,2,3) should switch rows two and three in the matrix. Your subroutine should work with any size matrix. If you need to have other arguments to the subroutine that give the dimensions for the matrix, that is o.k. Your main program should only have the data for the matrix, print the original matrix and then print the matrix after the subroutine is called, showing that the rows were switched. Test it on at least two matrices of with different dimensions. Your subroutine should check that the the numbers that are sent to switch the rows are valid, i.e., that neither is zero or less or greater than the number of rows.

Individual Promlem: Do the same as the collaborative problem, but switch two columns instead.
Bill Goodwine, 376 Fitzpatrick
cdiberna

Re: Homework 8, due November 18.

Post by cdiberna »

Prof. Goodwine,

I'm having trouble determining the size of my matrix so I can run the program to swap rows. Is there a built in function in FORTRAN that can do that, or do you have any hints that could help lead me to an answer? Thanks!
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 8, due November 18.

Post by goodwine »

cdiberna wrote:Prof. Goodwine,

I'm having trouble determining the size of my matrix so I can run the program to swap rows. Is there a built in function in FORTRAN that can do that, or do you have any hints that could help lead me to an answer? Thanks!
You are always going to have to know the size of the matrices. For example, for the last homework in this course you will read in the size of the matrix before you actually load the data. So, for this homework it's ok to pass the matrix dimensions as an argument to the subroutine.
Bill Goodwine, 376 Fitzpatrick
kmurph24

Re: Homework 8, due November 18.

Post by kmurph24 »

Is it alright if we write the matrix into our program or does it need to be inputed by the user?
sschwane

Re: Homework 8, due November 18.

Post by sschwane »

I wrote the program, and my code works until I put it into a subroutine. Instead of swapping the values of rows in my matrix, it simply returns a matrix full of zeroes. Do you have any ideas of common mistakes that would cause this problem?
Thanks
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 8, due November 18.

Post by goodwine »

kmurph24 wrote:Is it alright if we write the matrix into our program or does it need to be inputed by the user?
You may code it into the program.
Bill Goodwine, 376 Fitzpatrick
goodwine
Site Admin
Posts: 1596
Joined: Tue Aug 24, 2004 4:54 pm
Location: 376 Fitzpatrick
Contact:

Re: Homework 8, due November 18.

Post by goodwine »

sschwane wrote:I wrote the program, and my code works until I put it into a subroutine. Instead of swapping the values of rows in my matrix, it simply returns a matrix full of zeroes. Do you have any ideas of common mistakes that would cause this problem?
Thanks
The only mistake I can think of is that you call the matrix something else in the subroutine but don't use the original name in the program. For example

X = the matrix you want to manipulate
Y = a matrix of zeros that you are going to
print x (prints what it is)
call subroutine(X,other stuff)
print Y (prints zeros)

subroutine(Y,other stuff)
switch the rows of Y
return

The reason this prints Y is that in the subroutine what you call Y is really X.
Bill Goodwine, 376 Fitzpatrick
jgalezie

Re: Homework 8, due November 18.

Post by jgalezie »

Homework for John Galeziewski
You do not have the required permissions to view the files attached to this post.
jgalezie

Re: Homework 8, due November 18.

Post by jgalezie »

sorry about that
Post Reply

Return to “AME 20214, Homework 8”