-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacob.mod.f90
executable file
·69 lines (57 loc) · 1.4 KB
/
jacob.mod.f90
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
! modulo com a declaração da subrotina que calcula a jacobiana do
! sistema
module jacob
use tipos, only : dp
implicit none
private
public :: jacobian
contains
!!$
!!$ subroutine jacobian( fex, n, x, t, jac )
!!$ external fex
!!$
!!$ integer, intent(in) :: n
!!$ real(dp), dimension(n), intent(in) :: x
!!$ real(dp), intent(in) :: t
!!$ real(dp), dimension(n,n), intent(out) :: jac
!!$
!!$ real(dp), parameter :: h = 1.0d-3
!!$ real(dp), dimension(n) :: xdot, xdot2, x2
!!$ real(dp) :: aux
!!$ integer :: i
!!$
!!$ x2 = x
!!$ call fex(n,t,x2,xdot)
!!$
!!$ do i = 1, n
!!$ aux = x2(i)
!!$ x2(i) = x2(i) + h
!!$ call fex(n,t,x2,xdot2)
!!$ jac(:,i) = ( xdot2 - xdot ) / h
!!$ x2(i) = aux
!!$ end do
!!$
!!$ return
!!$ end subroutine jacobian
subroutine jacobian( fex, n, x, t, jac )
external fex
integer, intent(in) :: n
real(dp), dimension(n), intent(in) :: x
real(dp), intent(in) :: t
real(dp), dimension(n,n), intent(out) :: jac
real(dp), parameter :: h = 1.0d-3
real(dp), dimension(n), save :: xdot, xdot2, x2
real(dp) :: aux
integer :: i
x2 = x
call fex(n,t,x2,xdot)
do i = 1, n
aux = x2(i)
x2(i) = x2(i) + h
call fex(n,t,x2,xdot2)
jac(:,i) = ( xdot2 - xdot ) / h
x2(i) = aux
end do
return
end subroutine jacobian
end module jacob