Você está na página 1de 3

Excel and Mathcad Tutorial On Iterative Solutions of Nonlinear Equations In this tutorial, a number of iterative techniques are to be used

to solve a nonlinear equation in a single variable. The general problem is


f ( x) = 0 find x

A specific example that will be used throughout this tutorial is the solution of the equation
!0 x + x " =

To put this into the form of the general problem, put all terms on the #$% of the equation
f ( x) = !0 x + x " =0

The solution is x = 0.&'!' " (to six significant figures). Method of Bisections The first step in this method is to discover two values of x that brac(et the solution, i.e., f(x) is positive for one of the values and negative for the other. %ince we (now the solution, lets assume we have discovered that x = 0 and x = ! brac(et the solution. )onstruct a table in an *xcel +or(sheet with a title ,-ethod of .isections/ and table headings x!, x', f!, f'. 0ut 0 and ! in the first two cells under the headings. T1pe in the formula for f(x) in the box under f!, using the cell containing x!, and use the same logic to get f'. 0ut 0." in as the next value of x! and drag the formula for f! down to evaluate the function at this bisection value. If it is still negative, as it should be, then 0." and ! will brac(et the solution, and 1ou can put a ! in for x'. The bisection for this new interval is 0. ", and the process can be continued. %ee if 1ou can carr1 out these stepwise calculations for six iterations. 2our answer will be the bisection of the last x!3x' interval in 1our table (their average). )ompare 1our result with the solution given above. To how man1 significant figures is 1our solution accurate4 Newton Iteration )an 1ou differentiate the function f ( x) 4 The result is f ( x ) = !0 x Ln(!0) + " x 5 . The 6ewton recursion formula is xnew = xold f ( xold ) 7 f ( xold ) . )onstruct a table in the same *xcel +or(sheet with an appropriate title and table headings x, f(x), f(x). Assume an initial value of x = ! . T1pe in the formulas for the

function and its derivative. T1pe in the formula for the new x value in terms of the previous one, and the previous values of the function and its derivative. Then, drag the formulas down one row to completel1 fill in values for the 'nd row of the table. If 1ou do this correctl1, 1ou should be able to grab the 'nd row cells and drag down all three columns at once, until 1ou are satisfied that 1ou have convergence. 8or this problem, with an initial guess of x = ! , five iterations are sufficient to obtain the answer to six significant figures. Tr1 different initial guesses. All 1ou should have to do is to put a different value in the first box for x. +hat can 1ou conclude about convergence of this method4 $ow could 1ou find a good initial guess for an1 function4 +hat about a plot4 +hat would 1ou plot versus what4 )an 1ou do this in *xcel4 Use of Solver in Excel 0ut a title for this method in 1our spreadsheet and the column headings x and f(x). 0ut 1our initial guess in the !st cell under x. T1pe the function in the !st box under f(x), using 1our initial guess for x. Then, under the Tools menu, bring up %olver. 9se %olver to ma(e the cell with the function go to :ero, b1 changing the value of x. -a(e sure 1ou get the solution indicated above. Tr1 different initial guesses. 6ote that 1ou have to call up %olver each time to resolve the problem with each new initial guess. )all up the %olver tool again and clic( ;ptions. 6ote the -ethod being used (6ewton). It is the same as 1ou <ust programmed above= Use of Find in Mathcad This problem can be solved in -athcad b1 use of a %olve .loc(> ?ive the variable x an initial value (x>@!). 6ote> t1pe a coln (>) for equal sign. T1pe the word ?iven (This starts the %olve .loc(.) T1pe in the equation, with a )trlA@ for the equal sign %et a variable equal to 8ind(x), e.g., x>@8ind(x) T1pe x@ to see the resulting value Beformat the answer to get six sig figs. 2ou should get x@0.&'!' C Successive Substitution Becast the problem to obtain a function that should be equal to x. 8or our general problem, this would be g ( x) = f ( x) + x = !0 x + x " + x . The method of successive substitution involves ma(ing an initial guess for x, plugging it into the equation for g(x), and using this value as the next guess, plugging it bac( in, etc.

This method wor(s well when the function is nearl1 linear in x. +e should not expect good results for our highl1 nonlinear equation. #ets tr1 it. )onstruct a table in an *xcel %preadsheet D give it an appropriate title and column headings x and g(x). 0ut 1our initial guess in the box under x, and t1pe in the formula for g(x). Then, ma(e the next x equal to the previous g(x). Erag the formula down one row, then grab both cells and drag down a wa1s. EonFt expect convergence, because it will not happen for this problem= We stein !l orith" This method uses successive substitution to get started for the first iteration, then uses an accelerated convergence scheme from there on. %ee Appendix A.'g (p. C! ) in the 8elder and Bousseau text for details of the formulas, but note that the1 use the notation f(x) where we are using g(x). )onstruct a table in *xcel, with an appropriate title for this method, and with column headings x, g(x), w, and q. 0ut in 1our initial guess for x, then t1pe in the formula for g(x). #eave the w and q cells blan( on this !st row. 9se a formula to set the 'nd x equal to the !st g(x). 6ote that this is using successive substitution. Erag down the formula for g(x) and t1pe in the formulas for w and q as given here>
g x w q= w ! w=

The values mean the difference between the value on the current row and the value on the previous row. The next x is calculated as (Grd row)
xnew = qxold + (! q ) g ( xold )

?rab the next three cells in the 'nd row and drag down one row. ?rab all four cells in the Grd row and drag down until convergence is obtained.

Você também pode gostar