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 • 15Note that SirIsaac is independent of the name g. Thus, you canchange g without breaking SirIsaac. You can find a good approximatesolution to x − cos(x) = 0 in a few iterations.> x0 := 1.0;x0 := 1.0> to 4 do x0 := SirIsaac(x0) end do;x0 := 0.7503638679x0 := 0.7391128909x0 := 0.7390851334x0 := 0.7390851332A Shift OperatorConsider the problem of writing a procedure that takes a function, f, asinput and returns a function, g, such that g(x) = f(x + 1). You can writesuch a procedure in the following manner.> shift := (f::procedure) -> ( x->f(x+1) ):Try performing a shift on sin(x).> shift(sin);x → sin(x + 1)Maple lexical scoping rules declare the f within the inner procedureto be the same f as the parameter within the outer procedure. Therefore,the shift command works as written.The previous example of shift works with univariate functions butit does not work with functions of two or more variables.> h := (x,y) -> x*y;h := (x, y) → x y> hh := shift(h);

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

Saved successfully!

Ooh no, something went wrong!