I was recently asked by a class to go over the Newton-Raphson method for solving non-linear equations. Specifically in this case it was to solve 1D gas dynamics equations. Here I will just do a brief overview of the method, and how its used. I will solve two cases, one where the derivative of the function is known, and one where the derivative of the function should be approximated.
Here are the contents you’ll find in this post:
- Introduction to the Newton-Raphson Method
- Using the Method
- Example 1 (derivative of the function is known)
- Calculating Mach number from critical area ratio (M from A/A*)
- Example 2 (derivative of the function is unknown… or to annoying to derive)
- Calculating incident shock pressure ratio from diaphragm pressure ratio
- Example 1 (derivative of the function is known)
- Conclusions and Useful References
Introduction to the Newton-Raphson Method
What is the Newton-Raphson method? Basically it is an iterative approach for solving the roots of functions. There are tons of these. You probably don’t need to know all of them (just pick a few that work for you!) Typically I stick to the Newton-Raphson method and the bisection method and I rarely have problems.
The Newton-Raphson method is used when you have some function f(x) and you want to find the value of the dependent variable (x) when the function equals zero. AKA you want to find the roots of the equation. If you have an initial guess at some point, , the tangent can be extended to some point that crosses 0 at an easily calculable point . This point gives an improved estimation of the root. The basics of the method come from the fact that the first derivative is equivalent to the slope and therefore if you know it, you can calculate the tangent intersection:
Which we can rearrange to get the “Newton-Raphson Formula”:
The method is depicted in the figure below:
Equation 2 pretty much sums up the method. If you start with a known derivative and function value you can calculate a new prediction . By repeating this process (perform iterations) better and better approximations of the value for x are obtained.
Using the Method
Example 1 (derivative of the function is known):
Lets say for this example that we know a critical area ratio (let’s say A/A*=3.3, with ) at a point in the flow field, and we want to use it calculate Mach number. For this we will solve the following equation:
This equation is equation for the critical area ratio for a given Mach number. Sometimes however the A/A* is known and the Mach number is desired. Let’s say A/A* =3.3 what is the Mach number? To do this, this equation can be easily solved using the Newton-Raphson approach.
Essentially the Newton-Raphson method is a root finding method. This means we are finding where an equation crosses zero. So how do we apply this to the problem above? We aren’t interested in where the equation above crosses zero, we are interested in where it crosses 3.3! Well it’s easy to change the above equation to give:
So now the problem is in a form that we can use the Newton-Raphson approach. In general, the approach is written as:
Here, f(x) is the equation that is to be solved (in our case Equation 4), x is the variable to be solved for (in our case Mach number) and df/dx is the derivative of the equation with respect to the unknown variable (in our case the derivative of Equation 4 with respect to Mach number).
So at this point we know f(M), but we must calculate the derivative of f(M). The result is the following:
The next step is to apply the iterative algorithm. Essentially, you have to make an intelligent initial guess for the unknown variable (Mach number). In our case let’s make our first guess M=3. In our first step this is . Using this value we can get a guess for . Then at our next iteration becomes and this process is repeated until convergence ().
The following is a table showing the convergence of this problem:
So the Mach number for an A/A* of 3.3 is 2.738! But what if we had chosen a different starting point? Say… 0.5? Well then the answer looks like…
Wait why is the answer different?? Dont forget! There are two solutions to this problem, a subsonic and a supersonic solution. When we started at M=3 we converged on the supersonic solution (M=2.73805). When we start at 0.5 we converged on the subsonic solution (M=0.17875).
Example 2 (derivative df/dx is unknown… or too annoying to derive):
For example 2 we are again going to solve a simple 1D gas dynamics problem using the Newton-Raphson method. For this problem, let’s say that we are given a diaphragm pressure ratio for a shock tube (). We want to solve for the pressure ratio that will exist across the normal shock that is created when the diaphragm ruptures. For this problem see John and Keith (2006) for an excellent chapter on the shock-tube problem.
Basically this problem boils down to solving the following equation
for a with a known shock tube pressure ratio . Equation 5 is not the type of equation that is very attractive to differentiate, so in this example we will use a simple central different to approximate the derivative. Essentially what this means is that instead of directly calculating the derivative at each of our iterations, we will use a point slightly to the right and slightly to the left in order to approximate the slope.
First of all we rearrange (5) to give us an equation that equals zero (so that we can find its roots). Demonstrating this is easier if we set our unknown .
For the Newton-Raphson the above equation would be solved using:
Since we do not know the derivative of f approximate it with a central difference (centered approximation of the local slope at that point):
With the above iterative equation, the problem is solved in the same fashion as Example 1. See the following table:
Using Newton-Raphson we have now calculated that for a diaphragm pressure ratio of 40, the pressure ratio across the shock () should be 4.7726.
Conclusion and Useful References
Hopefully this was helpful. The Newton-Raphson method is extremely useful. However be careful! There are some cases where this method doesn’t work very well. For example if an equation has multiple roots, your initial guess must be fairly close to the answer you are looking for or you could get the completely wrong root. It often helps to plot your function beforehand or after so that you know what it looks like, and it also helps to never blindly trust the answer. If it isn’t physical… it probably isn’t the one you were looking for.
Also the wikipedia page on this is pretty good… haha
Here are some useful references
 John, J. E. A., & Keith, T, G. (2006) Gas Dynamics, 3rd Edition, Pearson Prentice Hall
 Chapra, S. C., Canale, R. P. (2010) Numerical Methods for Engineers (6th Ed.), McGraw-Hill