This repository contains implementations of Newton's method using PyTorch for both single-variable and multi-variable optimization problems.
newton.py- Implementation of Newton's method for single-variable functionsnewton_multivariable.py- Implementation of Newton's method for multi-variable systems of equationsloss_backword.py- Example using PyTorch's autograd for gradient computation
The newton_multivariable.py file implements Newton's method to find the intersection of:
- A circle: x₁² + x₂² = 4
- A parabola: x₁ = x₂²
The implementation provides two solution approaches:
- Using
torch.linalg.solveto solve the linear system J * dx = y - Using matrix inversion with
torch.linalg.invto compute x_new = x - J⁻¹y
Key features:
- Automatic differentiation with
torch.autograd.functional.jacobian - Custom implementation of the Jacobian matrix
- Convergence checking with tolerance
- Maximum iteration limit
- Python 3.x
- PyTorch
To run the multi-variable Newton's method:
python newton_multivariable.pyThe implementation will find the intersection points of the circle and parabola, demonstrating the convergence of Newton's method for systems of nonlinear equations.