Reputation: 188
This is my Fortran 90 program for Newton-Raphson method. However, it did not compile properly and gave this warning in geany
newraph.f90:18.17:
real function f(x)
1
Warning: Unused dummy argument 'x' at (1)
newraph.f90:18.15:
real function f(x)
1
Warning: Return value of function 'f' at (1) not set
Compilation finished successfully.
program newton_raphson
implicit none
real,parameter::error=1e-4
integer::i
real::xo,x1,f,fd
read*,xo
i=1
10 x1=xo-(f(xo)/fd(xo))
if(abs((x1-xo)/x1)<error) then
print*,"root is", x1,"no. of iteration=",i
else
xo=x1
i=i+1
goto 10
endif
end
real function f(x)
real::x
end
real function fd(x)
real::x
fd=3*x**2-1
end
Upvotes: 2
Views: 964
Reputation: 59998
You have just two warnings. Both just inform you that the function f
does nothing:
real function f(x)
real::x
end
Change it to return something useful and the warnings will vanish.
real function f(x)
real, intent(in) :: x
f = x**2
end function
and then change fd
to return the derivative of f
, like fd = 2*x
.
Other than that, try to use some decent programming style. Use indentation, use loops instead of go to
where possible. Use vertical spacing (empty lines). Also it is better to use end function
, end subroutine
and end program
for clarity.
Upvotes: 3