Help with a very simple fortran program.

  • Context: Fortran 
  • Thread starter Thread starter tactical
  • Start date Start date
  • Tags Tags
    Fortran Program
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 3K views
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.
 
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. :)