Page 1 of 1
Homework 8, due November 18.
Posted: Thu Nov 11, 2010 11:06 am
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.
Re: Homework 8, due November 18.
Posted: Sat Nov 13, 2010 11:48 am
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!
Re: Homework 8, due November 18.
Posted: Sat Nov 13, 2010 7:34 pm
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.
Re: Homework 8, due November 18.
Posted: Tue Nov 16, 2010 12:39 am
by kmurph24
Is it alright if we write the matrix into our program or does it need to be inputed by the user?
Re: Homework 8, due November 18.
Posted: Tue Nov 16, 2010 1:06 am
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
Re: Homework 8, due November 18.
Posted: Tue Nov 16, 2010 6:54 am
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.
Re: Homework 8, due November 18.
Posted: Tue Nov 16, 2010 6:59 am
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.
Re: Homework 8, due November 18.
Posted: Thu Nov 18, 2010 11:21 am
by jgalezie
Homework for John Galeziewski
Re: Homework 8, due November 18.
Posted: Thu Nov 18, 2010 11:24 am
by jgalezie
sorry about that