Help with a very simple fortran program.

  • Context: Fortran 
  • Thread starter Thread starter tactical
  • Start date Start date
  • Tags Tags
    Fortran Program
Click For Summary
SUMMARY

The discussion revolves around creating a Fortran program to multiply an NxN matrix by an N-dimensional vector. The user provides a basic structure using Fortran 77, including the initialization of the matrix and vector, as well as the computation of the solution vector. Key functions such as RAND() for random number generation and SYSTEM_CLOCK for seeding are mentioned. The code structure includes nested loops for matrix and vector initialization and multiplication, emphasizing the need for debugging and validation of results.

PREREQUISITES
  • Understanding of Fortran 77 syntax and structure
  • Familiarity with matrix and vector operations
  • Knowledge of random number generation in Fortran
  • Basic debugging techniques in programming
NEXT STEPS
  • Study Fortran 77 matrix manipulation techniques
  • Learn about random number generation functions in Fortran
  • Explore nested loops and their applications in Fortran
  • Research debugging methods specific to Fortran programming
USEFUL FOR

This discussion is beneficial for engineering students, Fortran programmers, and anyone looking to understand matrix operations and random number generation in Fortran.

tactical
Messages
6
Reaction score
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
"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. :)
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 22 ·
Replies
22
Views
5K
  • · Replies 21 ·
Replies
21
Views
3K