Professional Documents
Culture Documents
Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Newtons Method
Newtons Method (also know as the NewtonRapshon Method) is another widely-used algorithm for finding roots of equations In this method, the slope (derivative) of the function is calculated at the initial guess value and projected to the x-axis The corresponding x-value becomes the new guess value The steps are repeated until the answer is obtained to a specified tolerance
Engineering Computation: An Introduction Using MATLAB and Excel
Newtons Method
y(xi)
Initial guess xi
Engineering Computation: An Introduction Using MATLAB and Excel
Newtons Method
y(xi)
xi
y(xi)/y(xi)
Engineering Computation: An Introduction Using MATLAB and Excel
Initial guess = 10
x = -2.0764
x = 1.4187
x = 5.6577
Engineering Computation: An Introduction Using MATLAB and Excel
In-Class Exercise
Draw a flow chart of Newtons Method Write the MATLAB code to apply Newtons Method to the previous example:
Output root x
Engineering Computation: An Introduction Using MATLAB and Excel
MATLAB Code
MATLAB functions defining the function and its derivative:
MATLAB Code
MATLAB Results
>> Newton Enter initial guess 10 Root found: 5.6577 >> Newton Enter initial guess 0 Root found: 1.4187 >> Newton Enter initial guess -10 Root found: -2.0764
Engineering Computation: An Introduction Using MATLAB and Excel
Excel Tools
We have seen how to use Solver for a system of equations; we can easily apply it to find roots of a single equation There is a tool in Excel even easier to use for a single equation: Goal Seek With Goal Seek, we instruct Excel to change the value of a cell containing the independent variable to cause the value of the cell containing the function to equal a given value
Engineering Computation: An Introduction Using MATLAB and Excel
fzero Example
The MATLAB function fzero finds the root of a function, starting with a guess value Example: function fun1 defines this equation:
fzero Example
The function fzero has arguments of the name of the function to be evaluated and a guess value:
>> fzero('fun1',10) ans = 5.6577
fzero Example
If a range is specified, then the function must have opposite signs at the endpoints
> fzero('fun1',[0 10]) ??? Error using ==> fzero at 292 The function values at the interval endpoints must differ in sign.
3 real roots
1 real root
roots Example
For polynomials, the MATLAB function roots finds all of the roots, including complex roots The argument of roots is an array containing the coefficients of the equation For example, for the equation
roots Example
>> A = [3, -15, -20, 50]; >> roots(A) ans = 5.6577 -2.0764 1.4187
roots Example
Now find roots of
>> B = [3, -5, -20, 50]; >> roots(B) ans = -2.8120 2.2393 + 0.9553i Two complex roots 2.2393 - 0.9553i
Engineering Computation: An Introduction Using MATLAB and Excel
Summary
The bisection method and Newtons method (or secant method) are widely-used algorithms for finding the roots of equations When using any tool to find the roots of non-linear equations, remember that multiple roots may exist The initial guess value will affect which root is found