-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ1.f90
174 lines (169 loc) · 3.73 KB
/
Q1.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
PROGRAM difference
real*8::h,diff31,diff32,diff51,diff52,t,e31,e32,e51,e52,miner31,miner32,miner52,miner51,h31,h32,h51,h52
real*8::d31(0:20,0:20),d32(0:20,0:20),d51(0:20,0:20),d52(0:20,0:20)
miner31=100000
miner32=100000
miner51=100000
miner52=100000
h31=2
h32=2
h51=2
h52=2
h=1
t=0
d31=0
d32=0
d51=0
d52=0
do n=0,20
diff31=(exp(t+h)-exp(t-h))/(2*h)
d31(n,0)=diff31
e31=abs(diff31-1)
diff32=((exp(t+h))-(2*(exp(t)))+exp(t-h))/(h*h)
d32(n,0)=diff32
e32=abs(diff32-1)
diff51=((exp(t-2*h))-(8*(exp(t-h)))+(8*(exp(t+h)))-(exp(t+2*h)))/(12*h)
d51(n,0)=diff51
e51=abs(diff51-1)
diff52=(-(exp(t-2*h))+(16*exp(t-h))-(30*(exp(t)))+(16*(exp(t+h)))-exp(t+(2*h)))/(12*h*h)
d52(n,0)=diff52
e52=abs(diff52-1)
print *,diff31,diff32,diff51,diff52
if (e31<miner31) then
miner31=e31
h31=h
endif
if (e32<miner32) then
miner32=e32
h32=h
endif
if (e51<miner51) then
miner51=e51
h51=h
endif
if (e52<miner52) then
miner52=e52
h52=h
endif
h=h/2
enddo
PRINT *,"OPTIMAL h for 1st derivative 3 point is",h31, "with error",miner31
PRINT *,"OPTIMAL h for 2nd derivative 3 point is",h32, "with error",miner32
PRINT *,"OPTIMAL h for 1st derivative 5 point is",h51, "with error",miner51
PRINT *,"OPTIMAL h for 2nd derivative 5 point is",h52, "with error",miner52
do i=1,20
do j=1,i-1
d31(i,j)=d31(i,j-1)+(d31(i,j-1)-d31(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d31(i,j), j=0,5)
enddo
do i=1,20
do j=1,i-1
d32(i,j)=d32(i,j-1)+(d32(i,j-1)-d32(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d32(i,j), j=0,5)
enddo
do i=1,20
do j=1,i-1
d51(i,j)=d51(i,j-1)+(d51(i,j-1)-d51(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d51(i,j), j=0,5)
enddo
do i=1,20
do j=1,i-1
d52(i,j)=d52(i,j-1)+(d52(i,j-1)-d52(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d52(i,j), j=0,5)
enddo
miner31=100000
miner32=100000
miner51=100000
miner52=100000
h31=2
h32=2
h51=2
h52=2
t=1.56
h=0.01
d31=0
d32=0
d51=0
d52=0
do n=0,20
diff31=(tan(t+h)-tan(t-h))/(2*h)
d31(n,0)=diff31
diff32=((tan(t+h))-(2*(tan(t)))+tan(t-h))/(h*h)
d32(n,0)=diff32
diff51=((tan(t-2*h))-(8*(tan(t-h)))+(8*(tan(t+h)))-(tan(t+2*h)))/(12*h)
d51(n,0)=diff51
diff52=(-(tan(t-2*h))+(16*tan(t-h))-(30*(tan(t)))+(16*(tan(t+h)))-tan(t+(2*h)))/(12*h*h)
d52(n,0)=diff52
e31=abs(diff31-(1/cos(t))*(1/cos(t)))
e32=abs(diff32-(2*(1/cos(t))*(1/cos(t))*tan(t)))
e51=abs(diff51-(1/cos(t))*(1/cos(t)))
e52=abs(diff52-(2*(1/cos(t))*(1/cos(t))*tan(t)))
print *,diff31,diff32,diff51,diff52
if (e31<miner31) then
miner31=e31
h31=h
endif
if (e32<miner32) then
miner32=e32
h32=h
endif
if (e51<miner51) then
miner51=e51
h51=h
endif
if (e52<miner52) then
miner52=e52
h52=h
endif
h=h/2
enddo
print *,(1/cos(t))*(1/cos(t)),2*(1/cos(t))*(1/cos(t))*tan(t)
PRINT *,"OPTIMAL h for 1st derivative 3 point is",h31, "with error",miner31
PRINT *,"OPTIMAL h for 2nd derivative 3 point is",h32, "with error",miner32
PRINT *,"OPTIMAL h for 1st derivative 5 point is",h51, "with error",miner51
PRINT *,"OPTIMAL h for 2nd derivative 5 point is",h52, "with error",miner52
do i=1,20
do j=1,i-1
d31(i,j)=d31(i,j-1)+(d31(i,j-1)-d31(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d31(i,j), j=0,5)
enddo
do i=1,20
do j=1,i-1
d32(i,j)=d32(i,j-1)+(d32(i,j-1)-d32(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d32(i,j), j=0,5)
enddo
do i=1,20
do j=1,i-1
d51(i,j)=d51(i,j-1)+(d51(i,j-1)-d51(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d51(i,j), j=0,5)
enddo
do i=1,20
do j=1,i-1
d52(i,j)=d52(i,j-1)+(d52(i,j-1)-d52(i-1,j-1))/((4**(j))-1)
enddo
enddo
do i=0,5
print *,(d52(i,j), j=0,5)
enddo
end program difference