Skip to content

Instantly share code, notes, and snippets.

@komasaru komasaru/mv_product.f95

Last active Oct 5, 2018
Embed
What would you like to do?
Fortran 95 source code to compute the product of matrix and vetor.
!****************************************************
! 行列とベクトルの積を計算
! : y = A x
!
! date name version
! 2018.08.15 mk-mode.com 1.00 新規作成
!
! Copyright(C) 2018 mk-mode.com All Rights Reserved.
!****************************************************
!
program mv_product
implicit none
integer :: i, j, n
integer, parameter :: nmax = 100
real(kind=8) :: a(nmax, nmax), x(nmax), y(nmax), tmp
write (*,*) 'Input a dimension:'
read (*,*) n
write (*,*) 'Input a vector:'
read (*,*) (x(i), i = 1, n)
write (*,*) 'Input a matrix:'
do i = 1, n
read (*,*) (a(i, j), j = 1, n)
end do
! 組み込み関数を使用しない場合
!do i = 1, n
! tmp = 0
! do j = 1, n
! tmp = tmp + a(i, j) * x(j)
! end do
! y(i) = tmp
!end do
!
! 組み込み関数を使用する場合
y(1:n) = matmul(a(1:n, 1:n), x(1:n))
write (*,*) (y(i), i = 1, n)
stop
end program mv_product
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.