Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fortran 95 source code to compute inner-product of vetors(Ver.2).
!****************************************************
! ベクトルの内積を計算(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
You can’t perform that action at this time.