# Help with a very simple fortran program.

1. Jan 22, 2012

### tactical

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()

LOL, it's not much, but I have never done matrices in fortran before :/. Any insight is greatly appreciated.

2. Jan 28, 2012

### FourierFaux

"Do loops".

Pseudo code:

Code (Text):

! 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