Help with a very simple fortran program.

In summary, the speaker is an engineering major who needs help with a Fortran program for multiplying an NxN matrix by an N dimensional vector. They share the code they have so far and ask for insight and help with debugging. The expert summarizes the code and suggests it is the listener's assignment to debug it.
  • #1
tactical
6
0
Hey, been 6 semesters since I took a fortran class and it's come up again. I'm and engineering major so I don't know what about programming and what not.

Anyways, I need a program that multiplies an NxN matrix by an N dimensional vector. This is what I have so far:

Program Matrix

IMPLICIT NONE

REAL :: N ! Dimension of the NxN matrix
REAL :: RandVal !Random values to generate random matrix
REAL :: MatrixA !The matrix
REAL :: SEED !Used in generating random numbers

CALL SYSTEM_CLOCK(COUNT=SEED)
CALL SRAND(SEED)
RandVal=RAND()

WRITE (*,*) "Please define the size of your NxN Matrix"
READ (*,*) N

LOL, it's not much, but I have never done matrices in fortran before :/. Any insight is greatly appreciated.
 
Technology news on Phys.org
  • #2
"Do loops".

Pseudo code:

Code:
! This defines your vector/matrix size.
parameter (N = 2)

real MatrixA(N,N)
real V(N), SolV(N) 

! Rand stuff
!
! You fill in the blank

!  Init Matrix
do j = 1, N
do i = 1, N
MatrixA(i,j) = rand()
end do
end do

!  Init Vector 
do i = 1,N
V(i) = rand()
end do

! Init SolV
do i = 1,N
SolV(i) = 0
end do

! Now we solve the thing:
do j = 1,N
do i = 1,N
SolV(i) = SolV(i)+MatrixA(i,j)*V(i)  
end do
end do

print*, 'The solution vector is:  '
do i = 1,N
print*, SolV(i)
end do

!  Ask yourself:  Does this produce the right answer?

In a nutshell, that's what the code should roughly look like in fortran77. It's your assignment, therefore, I leave this for you to debug.

Have a good night. :)
 

1. What is Fortran and why is it used?

Fortran is a high-level programming language that is commonly used for scientific and engineering applications. It is designed to handle complex mathematical computations and has a large library of built-in functions for this purpose. Fortran is also known for its efficiency and speed in running calculations, making it a popular choice for scientific programming.

2. How do I write a simple Fortran program?

To write a simple Fortran program, you will need a text editor and a Fortran compiler. First, you will need to write your program in the text editor, following the syntax and structure of Fortran. Once your program is written, you can use the compiler to convert it into an executable file, which can then be run on your computer.

3. What are the basic elements of a Fortran program?

A Fortran program typically consists of a main program and one or more subroutines or functions. The main program is where the program execution begins, and it can call on subroutines or functions to perform specific tasks. Other elements of a Fortran program include variables, data types, control structures, and input/output statements.

4. How can I debug my Fortran program?

To debug a Fortran program, you can use a debugger tool that allows you to step through your code and identify any errors or bugs. Another helpful technique is to use print statements to output the values of variables at different points in your program. This can help you pinpoint where the problem is occurring and troubleshoot it.

5. Are there any resources available for learning Fortran?

Yes, there are many resources available for learning Fortran, including online tutorials, textbooks, and forums where you can ask for help and advice from other Fortran programmers. Additionally, many universities and colleges offer courses on Fortran programming. It is also helpful to practice regularly and work on simple programs to improve your skills.

Similar threads

  • Programming and Computer Science
Replies
4
Views
463
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
22
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
Back
Top