Last active
November 7, 2018 00:49
-
-
Save komasaru/abcef2d8dff24319269020ede8c624f4 to your computer and use it in GitHub Desktop.
Fortran 95 source code to compute inner-product of vetors(Ver.2).
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
!**************************************************** | |
! ベクトルの内積を計算(Ver.2) | |
! | |
! date name version | |
! 2018.08.20 mk-mode.com 1.00 新規作成 | |
! | |
! Copyright(C) 2018 mk-mode.com All Rights Reserved. | |
!**************************************************** | |
! | |
program inner_product_2 | |
implicit none | |
integer, parameter :: n = 3 | |
real(8) :: x(n) = (/ 1, 2, 3 /) | |
real(8) :: y(n) = (/ 4, 5, 6 /) | |
write (*,*) iprod(n, x, y) | |
write (*,*) dot_product(x, y) ! 組み込み関数で検算 | |
stop | |
contains | |
! 内積計算 | |
! | |
! :param(in) integer(4) dim | |
! :param(in) real(8) x(dim) | |
! :param(in) real(8) y(dim) | |
! :return real(8) | |
real(8) function iprod(dim, x, y) | |
implicit none | |
integer, intent(IN) :: dim | |
real(8), intent(IN) :: x(dim), y(dim) | |
integer :: i | |
iprod = 0 | |
do i = 1, dim | |
iprod = iprod + x(i) * y(i) | |
enddo | |
return | |
end function iprod | |
end program inner_product_2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment