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. :)
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

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