This repository contains an implementation of two numerical optimization methods — Grid Search and Newton-Raphson — for finding the maximum of a given mathematical function.
The project compares the performance of Grid Search and Newton-Raphson methods in optimizing a mathematical function f: R^2 -> R. Both methods compute the maximum value of the function within specific constraints and measure the number of function calls made during execution.
gridsearch
: Uses a brute-force grid search algorithm to find the maximum of the function ( f ) over a defined interval with a given precision.newton
: Implements the Newton-Raphson method to find the maximum of the function ( f ) using its gradient and Hessian matrix.
This project requires Python 3.x. No additional libraries are needed.
optimization_project.py
: Python script containing the implementations ofgridsearch
andnewton
functions.- Documentation: This README and the assignment description document provide details about the methods and implementation.
-
Clone this repository.
-
Open
optimization_project.py
in your favorite Python IDE or text editor. -
The code includes predefined test cases:
- Newton-Raphson:
Tests the method with an initial guess of ([0, 0]) and ( epsilon = 0.001 ).
newton([0,0], 0.001, f, f1, f2)
- Grid Search:
Tests the method over the interval ([-10, 10]) for both dimensions with a precision of ( 0.01 ).
gridsearch([-10,-10], [10,10], 0.01, f)
- Newton-Raphson:
-
Run the script:
python optimization.py