# Newton Raphson Optimization (Finding Min. or Max.)

by admin in Math, Statistics, and Optimization , MATLAB Family , Optimization on April 26, 2019This code uses Newton-Raphson method to find the optimum value (Finding Min. or Max.) of a given function within a predefined given interval.

**Code Outputs:**

- Optimal Value Location
- Optimal Value itself
- The Accuracy of Result
- Number of Iterations
- Chart for the Position of the Optimal Value on the Given Function
- Error Chart
- Chart of the Optimal Value Convergence
- Printed Values for (Optimal Value and Possition, Accuracy and Number of Iterations)

The Optimal Value is at: 1.4276 ,is: 1.7757 , NO Iterations: 4 , Accuracy: 9.0542e-05

**Required Inputs:**

- The function Wanted to be Optimized
- The Interval that you expect the optimal value located within it (make it large it you don’t know it)
- Minimal Accuracy of the Result
- Maximum Number of Iterations (The code has a self breaking algorithm when finding the answer)

**About the Method:**

**Newton’s method** is an iterative method for finding the roots of a differentiable function ** f**, which are solutions to the equation

**. In optimization, Newton’s method is applied to the derivative**

*f*(*x*) = 0**of a twice-differentiable function**

*f*′**to find the roots of the derivative (solutions to**

*f***), also known as the stationary points of**

*f*′(*x*) = 0**These solutions may be minima, maxima, or saddle points.**

*f*.

** Newton Raphson Optimization Method:**

In the one-dimensional problem, Newton’s method attempts to find the roots of ** f ′** by constructing a sequence

**from an initial guess**

*x*_{n}**that converges towards some value**

*x*_{0}**satisfying**

*x****. This**

*f*′(*x**) = 0**is a stationary point of**

*x****.**

*f*The second-order Taylor expansion ** f_{T }(x)** of a function

**around**

*f***is**

*x*_{n}Ideally, we want to pick a **Δ x **such that

**is a stationary point of**

*x*_{n}+ Δ*x***. Using this Taylor expansion as an approximation, we can at least solve for the**

*f***Δ**corresponding to the root of the expansion’s derivative:

*x*Provided the Taylor approximation is fairly accurate, then incrementing by the above Δ*x* should yield a point fairly close to an actual stationary point of ** f**. This point,

**, we define to be the**

*x*_{n+1}=*x*_{n}+ Δ*x*=*x*_{n}−*f*′(*x*_{n}) /*f*″(*x*_{n})**guess in Newton’s method; as**

*n*+ 1th**tends toward infinity,**

*n***should approach a stationary point**

*x*_{n}**of the actual function**

*x****. Indeed, it is proven that if**

*f***is a twice-differentiable function and other technical conditions are satisfied, the sequence**

*f***will converge to a point**

*x*_{1},*x*_{2}, …**satisfying**

*x****.**

*f*′(*x**) = 0

**Geometric interpretation:**

The geometric interpretation of Newton’s method is that at each iteration, ** f (x)** is approximated by a quadratic function around

**x**

_{n}, and a step is taken to the maximum or minimum of that quadratic function (in higher dimensions, this may also be a saddle point). Note that if

**happens to**

*f*(x)*be*a quadratic function, then the exact extremum is found in one step.

### Higher dimensions:

The above iterative scheme can be generalized to several dimensions by replacing the derivative with the gradient, **∇ f (x)**, and the reciprocal of the second derivative with the inverse of the Hessian matrix,

**H**

*f*(

**x**). One obtains the iterative scheme

Often Newton’s method is modified to include a small step size** γ ∈ (0,1)** instead of

*γ*= 1This is often done to ensure that the Wolfe conditions are satisfied at each step **x**_{n} → **x**_{n+1} of the iteration. For step sizes other than 1, the method is often referred to as the relaxed Newton’s method.

Where applicable, Newton’s method converges much faster towards a local maximum or minimum than gradient descent. In fact, every local minimum has a neighborhood *N*such that, if we start with **x**_{0} ∈ *N*, Newton’s method with step size** γ = 1** converges quadratically (if the Hessian is invertible and a Lipschitz continuous function of

**x**in that neighborhood).

Finding the inverse of the Hessian in high dimensions can be an expensive operation. In such cases, instead of directly inverting the Hessian it’s better to calculate the vector Δ*x* = **x**_{n + 1} – **x**_{n} as the solution to the system of linear equations

which may be solved by various factorizations or approximately (but to great accuracy) using iterative methods. Many of these methods are only applicable to certain types of equations, for example the Cholesky factorization and conjugate gradient will only work if [**H** *f*(**x**_{n})] is a positive definite matrix. While this may seem like a limitation, it’s often a useful indicator of something gone wrong; for example if a minimization problem is being approached and [**H** *f*(**x**_{n})] is not positive definite, then the iterations are converging to a saddle point and not a minimum.

On the other hand, if a constrained optimization is done (for example, with Lagrange multipliers), the problem may become one of saddle point finding, in which case the Hessian will be symmetric indefinite and the solution of **x**_{n+1} will need to be done with a method that will work for such, such as the **LDL**^{T} variant of Cholesky factorization or the conjugate residual method.

There also exist various quasi-Newton methods, where an approximation for the Hessian (or its inverse directly) is built up from changes in the gradient.

If the Hessian is close to a non-invertible matrix, the inverted Hessian can be numerically unstable and the solution may diverge. In this case, certain workarounds have been tried in the past, which have varied success with certain problems. One can, for example, modify the Hessian by adding a correction matrix *B*_{n} so as to make H*f*(**x**_{n}) + *B*_{n}positive definite. One approach is to diagonalize **H** *f*(**x**_{n}) and choose *B*_{n} so that **H** *f*(**x**_{n}) **+ B_{n}** has the same eigenvectors as

**H**

*f*(

**x**

_{n}), but with each negative eigenvalue replaced by

**ϵ > 0**.

An approach exploited in the Levenberg–Marquardt algorithm (which uses an approximate Hessian) is to add a scaled identity matrix to the Hessian, ** μI**, with the scale adjusted at every iteration as needed. For large

*μ*and small Hessian, the iterations will behave like gradient descent with step size

**1 /**. This results in slower but more reliable convergence where the Hessian doesn’t provide useful information.

*μ*

**References:**

[1] Avriel, Mordecai (2003). Nonlinear Programming: Analysis and Methods. Dover Publishing. ISBN 0-486-43227-0.

[2] Bonnans, J. Frédéric; Gilbert, J. Charles; Lemaréchal, Claude; Sagastizábal, Claudia A. (2006). Numerical optimization: Theoretical and practical aspects. Universitext (Second revised ed. of translation of 1997 French ed.). Berlin: Springer-Verlag. doi:10.1007/978-3-540-35447-5. ISBN 3-540-35445-X. MR 2265882.

[3] Fletcher, Roger (1987). Practical Methods of Optimization (2nd ed.). New York: John Wiley & Sons. ISBN 978-0-471-91547-8.

[4] Givens, Geof H.; Hoeting, Jennifer A. (2013). Computational Statistics. Hoboken, New Jersey: John Wiley & Sons. pp. 24–58. ISBN 978-0-470-53331-4.

[5] Nocedal, Jorge; Wright, Stephen J. (1999). Numerical Optimization. Springer-Verlag. ISBN 0-387-98793-2.

Share Now!