Find by Newton-Raphson method the real root of
3x - Cosx - 1 = 0 in the interval [1,2]
Program Fixed_method
Implicit none
Real :: l , m , c , g
Integer :: i
Write ( * , * ) ' Input interval a and b '
Read ( * , * ) l , m
Write ( * , 67 ) ' Number' , 'value of x' , 'value of f(x)' , 'Absolute error'
67 Format ( / , / , A7 , 7x , A11 , 5x , A14 , 2x , A15 )
c = l
do i = 1 , 100
g = ( c + 10.0 ) ** ( 1.0 / 4.0 )
Write ( * , 66 ) i , c , g , abs (c - g )
66 Format (2x , i3 , 11x , f8.6 , 8x , f8.6 , 8x , f8.6 )
If( abs ( c - g ) .le. 0.0000001 ) Exit
c = g
End do
Write( * , 21 ) ' The approximate root of the function is : ' , c
21 Format ( / , / , A42 , F12.9 )
End program
Subroutine func ( g , x )
Real,intent(in)::x
Real,intent(out)::g
g = x**4 - x - 10
End subroutine
Subroutine interval ( l , m )
Real , intent(in) : : l , m
Real :: g , h , x
call func ( g , l )
call func ( h , m )
k = g * h
If ( k .lt. 0 )then
x = l
Write ( * , * ) "There is a root in this interval . "
Else if ( k .gt. 0 ) then
x = 0
Write ( * , * ) 'There is no root in this interval . '
Elseif ( g == 0 ) then
Write( * , * ) g
Else
Write( * , * ) h
Endif
End Subroutine
Input :
Output :