11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.2 Procedures That Return Procedures • 1321.510.50–0.5–1x0x11 2 3 4x5 6 7 8To find a numerical solution to the equation f(x) = 0, guess an approximatesolution, x 0 , and then generate a sequence of approximationsusing:1. Newton’s method2. The following formulation of the previous processx k+1 = x k − f(x k)f ′ (x k )You can implement this algorithm on a computer in a number of ways.Example 1The following procedure takes a function and creates a new procedure,which takes an initial guess and, for that particular function, generatesthe next guess. The new procedure does not work for other functions. Tofind the roots of a new function, use MakeIteration to generate a newguess-generating procedure. The unapply command turns an expressioninto a procedure.> MakeIteration := proc( expr::algebraic, x::name )> local iteration;> iteration := x - expr/diff(expr, x);> unapply(iteration, x);> end proc:The procedure returned by the MakeIteration procedure maps thename x to the expression assigned to the iteration.Test the procedure on the expression x − 2 √ x.> expr := x - 2*sqrt(x);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!