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.
Homework 8, due November 18.
-
- Site Admin
- Posts: 1596
- Joined: Tue Aug 24, 2004 4:54 pm
- Location: 376 Fitzpatrick
- Contact:
Homework 8, due November 18.
Bill Goodwine, 376 Fitzpatrick
Re: Homework 8, due November 18.
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!
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!
-
- Site Admin
- Posts: 1596
- Joined: Tue Aug 24, 2004 4:54 pm
- Location: 376 Fitzpatrick
- Contact:
Re: Homework 8, due November 18.
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.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!
Bill Goodwine, 376 Fitzpatrick
Re: Homework 8, due November 18.
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.
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
Thanks
-
- Site Admin
- Posts: 1596
- Joined: Tue Aug 24, 2004 4:54 pm
- Location: 376 Fitzpatrick
- Contact:
Re: Homework 8, due November 18.
You may code it into the program.kmurph24 wrote:Is it alright if we write the matrix into our program or does it need to be inputed by the user?
Bill Goodwine, 376 Fitzpatrick
-
- Site Admin
- Posts: 1596
- Joined: Tue Aug 24, 2004 4:54 pm
- Location: 376 Fitzpatrick
- Contact:
Re: Homework 8, due November 18.
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 examplesschwane 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
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
Re: Homework 8, due November 18.
Homework for John Galeziewski
You do not have the required permissions to view the files attached to this post.