Engineering Applied Exercise


When trying to solve an equation f(x) = 0, you’ve generally used two possible approaches to solving it algebraically: (1) isolating the variable x, or (2) factoring the left-hand side (and then setting each factor to zero and solving via method (1)).  (If we count “guessing numbers for x and plugging them in to check”, then that would be method (3).)

 

There are functions f(x) that do not yield to either of those approaches; and if you are confronted with one of them, you will want some approach of finding a solution numerically.  Without resorting to full-on method (3) above, you can use calculus (and a somewhat random starting guess) to generate better and better guesses until you reach a number that is “close enough”.

Refining Your Guess

In order to turn your guess  for a solution into a better guess  for a solution, you should replace the difficult equation f(x) = 0 with the much easier equation L(x) = 0, where L(x) is the linearization of f(x) at your current guess point.  That is, you want L(x) to be the line through the point with a slope of .   If you write L(x) in slope-intercept form y = mx + b, then m is our slope , and b is whatever constant it needs to be to make the line L(x) meet the function f(x); solving for b, we see that

Since L(x) is a nice straight line, it is easy to see when L(x) = 0 algebraically; if we set y = 0 in the above and solve, we find that

When to Stop Refining Your Guess

You will need to know something about how your answer is going to be used in order to know when you have a sufficiently accurate guess for x; if all that really matters is the size of f(x), then you can iterate until f(x) is sufficiently small.  (If so, you might be a long way away from the “actual” x-intercept if the original function f(x) is nearly horizontal; but that’s why you want to be sure that the size of f(x) is what’s important.)  If you want to make sure your x-value itself is accurate, then you can repeat the process until your newly-generated guess for x is very close to the x you just used.  (And in particular (and particularly rare) circumstances, you might know that you have a fairly accurate starting point, and just decide to iterate once or twice without checking how close things are.)

 

 

What Could Go Wrong?

Because the formula for generating a new guess involves a division, if you end up with a point where  is zero, the new guess will not exist.  If  does exist but is very small, x1 may end up a long way away (and sometimes outside the domain of the function f).  It can be hard to predict when this will happen; if it does happen, generally picking a slightly different initial guess can bring thingsback to normal.

Automating the Procedure

If you are using a tool such as Scilab or a general programming/scripting language like C or Python, you can use a loop to repeatedly generate these guesses until your desired accuracy level is met.  (I would suggest setting up a function or procedure to calculate  and another to calculate , and use the functions inside your loop.)

A simple spreadsheet such as Excel can also be used by setting up a table: if one column holds the current guess , you can have formulas in the next columns to calculate , and , and then use this final value as the starting value for the next row (and copy the formulas down a row).  You will have to check the convergence of your x-values yourself and decide how many rows is enough.

 

Instructions

 

Consider the equation x sin x = 5, or in the notation above x sin x – 5 = 0.

  1. For this situation, what is f'(x)?
  2. Set up an Excel spreadsheet, or a program in your favorite programming language, to find solutions to the above equation. (Submit this file along with your answers to the questions.)
  3. Starting with a guess of x = 5, what solution does Newton’s method converge to? (Run the method until the x values don’t change in the first five decimal places.)
  4. There are five solutions to x sin x = 5 between x = 0 and x = 20 (it is at heart a sine wave, after all). By varying your initial guess, find them all to within five decimal places.