Fortran Help with a very simple fortran program.

  • Thread starter Thread starter tactical
  • Start date Start date
  • Tags Tags
    Fortran Program
AI Thread Summary
The discussion centers around creating a Fortran program to multiply an NxN matrix by an N-dimensional vector. The user, an engineering major with limited programming experience, shares their initial code and seeks guidance. The provided code includes the setup for generating a random NxN matrix and an N-dimensional vector, initializing them, and calculating the resulting vector through nested loops. Key points include the use of random number generation, matrix initialization, and the multiplication process. The user is encouraged to debug the code themselves, emphasizing the importance of understanding the logic behind the operations. The overall goal is to ensure the program correctly computes the product of the matrix and vector.
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. :)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
5
Views
5K
Replies
4
Views
2K
Replies
8
Views
2K
Replies
2
Views
1K
Replies
22
Views
5K
Replies
21
Views
3K
Back
Top