Last active
October 5, 2018 07:14
-
-
Save komasaru/977d19b1dcd8ad1ddd7ad4573714ca6e to your computer and use it in GitHub Desktop.
Fortran 95 source code to compute inner-product of vetors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!**************************************************** | |
! ベクトルの内積を計算 | |
! | |
! date name version | |
! 2018.08.14 mk-mode.com 1.00 新規作成 | |
! | |
! Copyright(C) 2018 mk-mode.com All Rights Reserved. | |
!**************************************************** | |
! | |
program inner_product | |
implicit none | |
integer :: i, dim | |
real(kind=8), allocatable :: v1(:), v2(:) | |
real(kind=8) :: tmp | |
write (*,*) 'Input dimension:' | |
read (*,*) dim | |
allocate(v1(dim), v2(dim)) ! メモリ確保 | |
write (*,*) 'Input vector 1:' | |
read (*,*) v1(1:dim) | |
write (*,*) 'Input vector 2:' | |
read (*,*) v2(1:dim) | |
! 組み込み関数を使用しない場合 | |
! tmp = 0 | |
! do i = 1, dim | |
! tmp = tmp + v1(i) * v2(i) | |
! end do | |
! | |
! 組み込み関数を使用する場合 | |
tmp = dot_product(v1, v2) | |
write (*,*) 'Inner product of v1 and v2 = ', tmp | |
deallocate(v1, v2) ! メモリ解放 | |
stop | |
end program inner_product |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment