NewtonRaphsonpg114.f90
I suggest you either typed this as it appears into the compiler, or as
an easier way, just copy and paste it!
Note: I do not claim
the program will 100% work, but I give it my best. If it doesn't, try tweaking
it yourself, or email me about it, and I'll modify and post the improved version
later. Good luck!
Program Newton_Raphson
implicit none
real :: a, b, c, counter_1, x, P, Q, S, Z, y, u, v, S1, S2, S3, S4&
&, T, T1, T2, H, H1, H2, H3, H4
real :: HA1, HA2, dp, dq, P1a, P1b
integer :: counter_2, counter_3, counter_5
character*2 choice
Print*, 'please choose the ways you want to differentiate your equation.'
counter_5 = 1
counter_3 = 1
counter_2 = 1
print *, ' please enter the value for guess value x. '
read *, x
print *, ' please enter the value for guess value y. '
read *, y
do while (counter_5 == 1)
counter_5 = 1
counter_3 = 1
counter_2 = 1
do while ( counter_2 <= 2 )
write (unit = *, fmt = 25), 'The', counter_2,'equation you want&
& to enter has x to the power upto how many??'
read *, a
counter_1 = 0
do while ( counter_1<=a )
c = a - counter_1
print *, 'Please key in the value for x**', c
read *, b
P = b*c
Q = c - 1
Z = P*x**Q
T = b*x**c
If ( counter_1 == 0 ) then
S = Z
H = T
print *, 's=', S
else
Z = Z + S
T = T + H
S = Z
H = T
End if
counter_1 = counter_1 + 1
end do
if ( counter_2 == 1 ) then
S1 = S
H1 = H
print*, 'S1=', S1
print*, 'H1=', H
else if (counter_2 == 2 ) then
S3 = S
H3 = H
print*, 'S3=', S3
print*, 'H3=', H3
end if
counter_2 = counter_2 + 1
end do
do while ( counter_3 <= 2)
write (unit = *, fmt = 25), 'The', counter_3,'equation you want&
& to enter has y to the power upto how many??'
read *, a
counter_1 = 0
do while ( counter_1<a )
c = a - counter_1
print *, 'Please key in the value for y**', c
read *, b
P = b*c
Q = c - 1
Z = P*y**Q
T = b*y**c
If ( counter_1 == 0 ) then
S = Z
H = T
print *, 's=', S
else
Z = Z + S
T = T + H
S = Z
H = T
End if
counter_1 = counter_1 + 1
end do
if ( counter_3 == 1 ) then
S2 = S
H2 = H
print*, 'S2=', S
print*, 'H2=', H
else if (counter_3 == 2 ) then
S4 = S
H4 = H
print*, 'S4=', S
print*, 'H4=', H4
end if
counter_3 = counter_3 + 1
end do
HA1 = H1 + H2
HA2 = H3 + H4
print*, HA1,',', HA2
!find inverse 2X2 matrix
dp = -S4*HA1/(S1*S4 - S2*S3) + (S2*HA2/(S1*S4 - S2*S3))
dq = S3*HA1/(S1*S4 - S2*S3) + (-S1*HA2/(S1*S4 - S2*S3))
PRINT*, 'dp=', dp
print*, 'dq=', dq
P1a = x + dp
P1b = y + dq
print*, ' |',P1a,'|'
write (unit=*, fmt=20), 'P1=', '|', '|'
print*, ' |',P1b,'|'
print*, ''
print*, " please enter 'go' proceed and find the next value or 'no' to stop the program"
read*, choice
if ( choice == 'go' ) then
x = P1a
y = P1b
counter_5 = 1
elseif ( choice == 'no' ) then
stop
end if
end do
20 format ( a3, 2x, a1, 15x, a1)
25 format ( a3, 1x, i1.0, 1x, a60 )
end program Newton_Raphson