-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw3.f
75 lines (52 loc) · 1.28 KB
/
hw3.f
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
c234567
program newton
implicit none
real*8 xx, expon, ct, expt, a(20)
integer i, nn
print *, 'Input the initial x'
read (*,*) xx
call facto(a)
nn=1000
call tangent(xx, ct)
open (111, file='result.dat')
write (111, '(A,1X,I4.4)') 'Number of iteration', nn
write (111, '(I4.4,1X,F10.5)') 0, xx
do i=1,nn
xx=xx-(expon(xx)-1)/ct
write (111, '(I4.4,1X,F10.5)') i, xx
end do
print *, 'The result is'
print *, xx
stop
end
c-----factorial function
subroutine facto(factorial)
integer i
real*8 factorial(20)
do i=1,20
factorial(i)=1
end do
do i=1,20
do j=1,i
factorial(i)=factorial(i)*j
end do
end do
return
end
c-----exponential function
real*8 function expon(x)
real*8 x, a(20)
integer i
call facto(a)
expon=1
do i=1,20
expon=expon+(x**i/a(i))
end do
return
end
c-----tangent line
subroutine tangent(x, coeff)
real*8 x, coeff, expon
coeff=expon(x)
return
end