A practice implementation of Newton's method for studying local convergence and numerical optimization in both univariate and multivariate cases.
The project explores how the familiar one-dimensional formulation of Newton's method generalizes to multiple dimensions through the Jacobian matrix, gradient vector, and Hessian matrix.
Newton's method is an iterative numerical method that can be used for both root finding and optimization. This project implements the method in two settings:
- Univariate: functions of a single variable
- Multivariate: functions of multiple variables
The univariate case uses the first and second derivatives, while the multivariate case extends these ideas using the Jacobian, gradient, and Hessian.
For a scalar function
The method uses the first derivative to approximate the function locally by its tangent line and iteratively improve the estimate of the root.
Newton's method can also be applied to finding extrema of a scalar function. Since an extremum occurs where
Here, the second derivative provides the curvature information used to update the current estimate.
For a system of nonlinear equations represented by a vector-valued function
In practice, the corresponding linear system is solved directly rather than explicitly computing the matrix inverse.
For a scalar function of several variables
where
- Newton's method for root finding in one dimension
- Newton's method for optimization in one dimension
- Multivariate Newton's method for solving nonlinear systems
- Multivariate Newton optimization
- Derivative-based iterative updates
- Jacobian matrices for nonlinear systems
- Gradient vectors for multivariate optimization
- Hessian matrices for second-order optimization
- Local convergence behavior
- Numerical stopping and convergence criteria
- Examples for experimentation and verification
Newton's method is primarily a locally convergent method. When the initial guess is sufficiently close to the desired solution and the relevant derivatives satisfy appropriate conditions, Newton's method can exhibit quadratic convergence.
However, convergence is not guaranteed for an arbitrary initial guess. Depending on the function and starting point, the iteration may converge to a different solution, fail to converge, or encounter numerical difficulties.
Although the mathematical formulation of Newton's method involves an inverse derivative, Jacobian, or Hessian, numerical implementations generally avoid explicitly computing matrix inverses. Instead, the Newton step is obtained by solving the corresponding linear system.
Important practical considerations include:
- Choice of initial guess
- Size of the Newton step
- Residual or gradient magnitude
- Singular or poorly conditioned Jacobians and Hessians
- Failure to converge
- Convergence to an unintended solution
- Numerical precision
The repository is organized as follows:
.
├── README.md
├── LICENSE
├── .gitignore
├── newton.py # Main implementation
├── newton2.py # Alternative implementation
├── multivariate.py # Multivariate Newton methods
├── test_newton.py # Unit tests
├── test_newton-2.py # Additional tests
├── newton-save.py # Saved/backup version
└── .ipynb_checkpoints/ # Jupyter notebook checkpoints (if any)
└── ...
git clone https://github.com/theorycs/newton-practice.git
cd newton-practiceThe core implementations are in the Python files. You can run the main scripts directly. For example, to execute the univariate implementation:
python newton.pyTo run the multivariate examples:
python multivariate.pyTo verify the implementations, run the test scripts:
python test_newton.py
python test_newton-2.pyThis project is written in Python and relies on standard libraries. If you need to install any dependencies, you can typically use:
pip install numpy matplotlib scipy # if needed(Check the individual script files for specific import statements.)
This repository is primarily a practice and learning implementation rather than a production numerical-analysis library. The goal is to connect the mathematical formulation of Newton's method with an actual implementation and to explore how the concepts of derivatives, Jacobians, gradients, and Hessians extend from one dimension to multiple dimensions.
The implementation is based on standard numerical analysis and optimization concepts, including Newton's method, local convergence, nonlinear systems, and second-order optimization.
This project is dedicated to the public domain under the CC0 1.0 Universal License. You can copy, modify, distribute, and perform the work, even for commercial purposes, all without asking permission.