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.

14 • Chapter 2: Procedures, Variables, and Extending Mapleexpr := x − 2 √ x> Newton := MakeIteration( expr, x);Newton := x → x − x − 2 √ x1 − 1 √ xNewton returns the solution, x = 4 after a few iterations.> x0 := 2.0;x0 := 2.0> to 4 do x0 := Newton(x0); end do;x0 := 4.828427124x0 := 4.032533198x0 := 4.000065353x0 := 4.000000000Example 2The MakeIteration procedure requires its first argument to be an algebraicexpression. You can also write a version of MakeIteration thatworks on functions. Since the following MakeIteration procedure recognizesthe parameter f as a procedure, you must use the eval commandto evaluate it fully.> MakeIteration := proc( f::procedure )> (x->x) - eval(f) / D(eval(f));> end proc:> g := x -> x - cos(x);g := x → x − cos(x)> SirIsaac := MakeIteration( g );SirIsaac := (x → x) − x → x − cos(x)x → 1 + sin(x)

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

Saved successfully!

Ooh no, something went wrong!