1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| !****************************************************
! ベクトルの内積を計算(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
|