-
Notifications
You must be signed in to change notification settings - Fork 1
/
calc.f90
144 lines (123 loc) · 3.66 KB
/
calc.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
! Copyright (C) 2003-2018 John Young, Matthew Worsley
!
! This file is part of mfit.
!
! Mfit is free software: you can redistribute it and/or modify it
! under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful, but
! WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
! General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see http://www.gnu.org/licenses/ .
program calc
use maths
implicit none
!variables
double precision :: nu, x, y, res
double precision, dimension(:,:), allocatable :: A
double precision, dimension(:), allocatable :: routput
integer :: i, j, n, p, k
character(len=1) :: choice
do i=1, 1000
print *,' '
print *,'----------------------------------------------------------------'
print *,'Select:'
print *,' '
print *,' a: bessel function of the 1st kind'
print *,' b: gamma function'
print *,' c: laguerre polynomial'
print *,' d: atan2'
print *,' e: factorial'
print *,' f: combinatorial'
print *,' g: bess1'
print *,' h: modulo'
print *,' i: (square) matrix inversion'
print *,' j: machine-dependent constants'
print *,'----------------------------------------------------------------'
1 read *,choice
print *,' '
select case (choice)
case('a')
print *,'bessel function: input order, real argument'
read *,nu,x
call bessel(nu-floor(nu), x, 1+floor(nu), routput)
print *,'result'
print *,routput(1+floor(nu))
if (allocated(routput)) deallocate(routput)
case('b')
print *,'gamma function : input argument'
read *,x
res = gamma(x)
print *,'result'
print *,res
case('c')
print *,'laguerre polynomial: input order, argument'
read *,n,x
call laguerre(n, x, routput)
print *,'result'
print *,routput(n)
if (allocated(routput)) deallocate(routput)
case('d')
print *,'atan2: input cmplx number re part, im part'
read *,x,y
print *,'result'
print *,atan2(y,x)
case('e')
print *,'factorial n!: input n'
read *,n
print *,'result'
print *,fact(n)
case('f')
print *,'combinatorial nCp: input n, p'
read *,n,p
print *,'result'
print *,comb(n,p)
case('g')
print *,'bess1: input x'
read *,x
print *,'result'
print *,bess1(x)
case('h')
print *,'a mod b: input a, b'
read *,x,y
print *,'result'
print *,modulo(x,y)
case('i')
print *,'(square) matrix A inv, order nxn: input n'
read *,n
allocate(A(n,n))
do j = 1, n
do k = 1, j
print *,'input element for row',j,'col',k
read *,x
A(j,k) = x
A(k,j) = x
end do
end do
print *,' '
print *,'input matrix:'
do j = 1, n
print *,A(j,:)
end do
call inv_mat(A)
print *,' '
print *,'output matrix:'
do j = 1, n
print *,A(j,:)
end do
deallocate(A)
case('j')
print *, 'machine_max', machine_max()
print *, 'machine_min', machine_min()
print *, 'machine_precision', machine_precision()
case default
print *,'ILLEGAL CHOICE'
goto 1
end select
end do
end program calc