MODULE func
!Create a module and name it. This will contain the function such that it is external to the nag routine
	IMPLICIT NONE
	!Assume nothing about the variables used within this module
	REAL(8) :: q
	!Declare a real kind 8 variable for q
CONTAINS
!State that the following functions/subroutines may be referenced by the module/program but do not run them
!explicitly until called
	REAL(8) FUNCTION f(x) RESULT(y)
	!Declare a function f with real kind 8 result y
		REAL(8), INTENT(IN) :: x
		!Declare a dummy variable x to be read in
		REAL(8) :: y
		!Declare a real variable kind 8 for the result
	
		y = EXP(q*x) - x**2
		!Calulate the value of the function
		
	END FUNCTION f
	!End the function
END MODULE func
!End the module

PROGRAM secant
!Initialise the program and name it
	USE func
	!State that we wish to use the module called func
	IMPLICIT NONE
	!Assume nothing about the variables within this program
	REAL(8) :: EPS, ETA, x
	!Declare real kind 8 variables for epsilon, eta and x for use within the nag routine
	INTEGER :: NFMAX, IFAIL
	!Declare integer variables for the max number of times to call the function within the nag routine
	!and an error variable
	
	EPS = 10.0_8**(-4.0_8)
	!Set epsilon to be 10^-4
	x = 1.0_8
	!Guess an initial value for x from which the iterative solution method will begin
	ETA = 0.0_8
	!Set a value for eta
	NFMAX = 1000
	!Set a value for NFMAX
	IFAIL = 1
	!Set IFAIL = 1 so that the nag routine runs correctly
	
	PRINT*, 'What is your value of q?'
	!Prompt the user to input a value for q
	READ*, q
	!Read the value into variable q
	
	CALL C05AJF(x, EPS, ETA, f, NFMAX, IFAIL)
	!Call the nag routine which uses an iterative method with the above variables to find a solution of the
	!function f = 0 with a tolerance of epsilon
	PRINT*, 'With epsilon = ', EPS, '  the root = ', x
	!Print the solution for the given epsilon
	
	!I looked at the bonus section and came to the conclusion that if I could find a useful condition for q
	!all that would be necessary to find both solutions would be to take two different starting values of x
	!and call the nag routine twice. Unfortunately I did not discover a useful condition for q.
	!I think it is as q approaches -infinity or 0 but I'm not certain.
	
END PROGRAM
!End the program
