nrm.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!
!Newton-Raphson Method for Numerical Methods
!Kumpulan 1
program nrm
implicit none
!declaration
integer::i, j, k, max=99, condition
real::alpha, beta, cancer, delta, dp, dq, dr, x, y, z, x1, y1, z1
real:: m21, m31, m32
real, dimension(3,4)::gauss
print*, "newton-raphson method."
233 print*, "pls enter initial value x, y, z"
read*, x, y, z
!equations
!sin(x)+y**2+log(z)-7=0
!3*x + 2**y +1-z**3=0
!x + y +z -5=0
do while (i<=max .or. condition==1)
!equations
alpha=sin(x)+y**2+log(z)-7
beta=3*x + 2**y +1-z**3
cancer=x + y +z -5
!jacobian
gauss(1,1)=cos(x)
gauss(1,2)=2*y
gauss(1,3)=1/z
gauss(1,4)=alpha
gauss(2,1)=3
gauss(2,2)=(2**y)*0.69314718
gauss(2,3)=-3*z**2
gauss(2,4)=beta
gauss(3,1)=1
gauss(3,2)=1
gauss(3,3)=1
gauss(3,4)=cancer
!gauss method
m21=3/cos(x)
m31=1/cos(x)
gauss(2,2)=gauss(2,2)-(m21*gauss(1,2))
gauss(2,3)=gauss(2,3)-(m21*gauss(1,3))
gauss(2,4)=gauss(2,4)-(m21*gauss(1,4))
gauss(3,2)=gauss(3,2)-(m31*gauss(1,2))
gauss(3,3)=gauss(3,3)-(m31*gauss(1,3))
gauss(3,4)=gauss(3,4)-(m31*gauss(1,4))
!m32=(cos(x)-2*y)/((2**y*)log(2)*COS(X)-6*y
m32=gauss(3,2)/gauss(2,2)
gauss(3,3)=gauss(3,3)-(m32*gauss(2,3))
gauss(3,4)=gauss(3,4)-(m32*gauss(2,4))
!back substitution
dr=gauss(3,4)/gauss(3,3)
dq=(gauss(2,4)-dr*gauss(2,3))/gauss(2,2)
dp=(gauss(1,4)-dr*gauss(1,3)-dq*gauss(1,2))/gauss(1,1)
x1=x+dp
y1=y+dp
z1=z+dp
delta=x1-x
if (abs(delta)<=10**(-6)) then
condition=1
else if (abs(delta)>=1) then
print*, "function is diverging."
goto 233
else
end if
x=x1
y=y1
z=z1
!counter
i=i+1
print*, x, y, z
end do
print*,"therefore, function value for ith iteration="
print*, "x", x
print*, "y", y
print*, "z", z
goto 233
end program nrm