Newton Raphson Method - nullstar/SecondBrain GitHub Wiki

Newton Raphson Method

Method

The Newton-Raphson method (also known as Newton's method) is a way to quickly find a good approximation for the root of a real-valued function $f(x) = 0$. It uses the idea that a continuous and differentiable function can be approximated by a straight line tangent to it.

Suppose you need to find the root of a continuous, differentiable function $f(x)$, and you know the root you are looking for is near the point $x = x_0$. Then Newton's method tells us that a better approximation for the root is $x_1 = x_0 - \frac{f(x_0)}{f'(x_0)}$. This process may be repeated as many times as necessary to get the desired accuracy. In general, for any $x$-value $x_n$, the next value is given by $x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$.

Note: the term "near" is used loosely because it does not need a precise definition in this context. However, $x_0$ should be closer to the root you need than to any other root (if the function has multiple roots)

Example

One example where this method is used is to estimate the eccentric anomaly $E$ in Keplers equation when working with Orbital Mechanics. Keplers equation is:

$$M = E - e\sin{E}$$

If we wish to estimate the value of $E$ given values for $M$ and $e$, first we re-arrange the equation into the correct format:

$$E - e\sin{E} - M = 0$$

Next we calculate the derivative of this equation which is:

$$1 - e\cos{E} = 0$$

Then we can use the following code which implements Newton Raphson Method to estimate $E$ to within a given error tolerance. Note that in this particular case, $M$ is a reasonable starting point for $E$.

float E = M;
constexpr float tolerance = 0.001f;
while (true)
{
	const float prevE = E;
	E = E - (E - e * sinf(E) - M) / (1.0f - e * cosf(E));
	if (fabsf(E - prevE) < tolerance)
		break;
}

Limitations

Newton's method may not work if there are points of inflection, local maxima or minima around $x_0$ or the root.

In situations like this, it will help to get an even closer starting point, where these critical points will not interfere.


#Math #Solver

⚠️ **GitHub.com Fallback** ⚠️