Hi! I'm doing a program for the product between a matrix and a vector, after i'll need also the product between two matrixes.
My compiler (silverfrost) doesn't work with this code but I think that it is all right :/
program matvett
!
! program for the product Mat x Vect
!
implicit none
integer nmax,mmax
parameter (nmax=20, mmax=20)
integer i,j, n,m
real A(nmax,mmax), xvet(mmax), yvet(nmax)
open(unit=8, file=C:\Users\ema\Desktop\ema.txt)
open(unit=9, file=C:\Users\ema\Desktop\risultato.txt)
read(8,*) n, m
write(9,*) 'Product matrix-vector'
write(9,*) 'Dimension matrix ', n, m
write(9,*) 'Matrix A:'
do i=1,n
read(8,*) (A(i,j),j=1,m)
write(9,*) ( A(i,j),j=1,m)
end do
write(9,*) 'Vector x:'
do i=1,m
read(8,*) xvet(i)
write(9,*) xvet(i)
end do
write(9,*) 'Vector product y:'
do i=1,n
! inizializziamo a 0. ciascuna componente del vettore prodotto
yvet(i)=0.0
!eseguiamo un ciclo do per j=1,m per calcolare le componenti
!del vettore prodotto
do j=1,m
yvet(i) = yvet(i) + A(i,j)*xvet(j)
end do
!scriviamo ciascuna componente sul file di risultati
write(9,*) yvet(i)
end do
close(8)
close(9)
end
My compiler (silverfrost) doesn't work with this code but I think that it is all right :/
program matvett
!
! program for the product Mat x Vect
!
implicit none
integer nmax,mmax
parameter (nmax=20, mmax=20)
integer i,j, n,m
real A(nmax,mmax), xvet(mmax), yvet(nmax)
open(unit=8, file=C:\Users\ema\Desktop\ema.txt)
open(unit=9, file=C:\Users\ema\Desktop\risultato.txt)
read(8,*) n, m
write(9,*) 'Product matrix-vector'
write(9,*) 'Dimension matrix ', n, m
write(9,*) 'Matrix A:'
do i=1,n
read(8,*) (A(i,j),j=1,m)
write(9,*) ( A(i,j),j=1,m)
end do
write(9,*) 'Vector x:'
do i=1,m
read(8,*) xvet(i)
write(9,*) xvet(i)
end do
write(9,*) 'Vector product y:'
do i=1,n
! inizializziamo a 0. ciascuna componente del vettore prodotto
yvet(i)=0.0
!eseguiamo un ciclo do per j=1,m per calcolare le componenti
!del vettore prodotto
do j=1,m
yvet(i) = yvet(i) + A(i,j)*xvet(j)
end do
!scriviamo ciascuna componente sul file di risultati
write(9,*) yvet(i)
end do
close(8)
close(9)
end