module Funkce

use std_type
private
public :: F, DF

contains

function F(x) result(v)
	! vraci funkci F u niz se hleda koren
	real(kind=DP),intent(in) :: x
	real(kind=DP) :: v
	v = x*(x*x-2)-5
end function F

function DF(x) result(v)
	! vraci derivaci dF/dx
	real(kind=DP),intent(in) :: x
	real(kind=DP) :: v
	v = 3*x*x-2
end function DF

end module funkce

program T_root


use std_type
use Funkce
use Root


real(kind=DP) :: x1,x2,xacc,koren,h
integer :: ierr, maxit


print *, "Zadej x1  x2  xacc  maxit" 
read *, x1, x2, xacc, maxit

if (x1==x2) then
	h = 0.0001_DP
	call Findb(h,x1,x2,F)
	print *,"x1 z Findb = ",x1
	print *,"x2 z Findb = ",x2
	print *,"Vystupni h = ",h
end if

print *
call RTBisect(x1,x2,xacc,koren,ierr,F,maxit)
print *,"Bisekce"
print *, "Koren = ",koren
print *, "ierr  = ",ierr
print *, "iteraci = ",maxit

print *
call RTSecant(x1,x2,xacc,koren,ierr,F,maxit)
print *,"Secny"
print *, "Koren = ",koren
print *, "ierr  = ",ierr
print *, "iteraci = ",maxit

print *
call RTNewton(x1,x2,xacc,koren,ierr,F,DF,maxit)
print *,"Newton"
print *, "Koren = ",koren
print *, "ierr  = ",ierr
print *, "iteraci = ",maxit



read *


end program T_root
