Sunday, March 11, 2012

Lazy analytic functions in Scala

During last week Jan and Veronica continued to explore Scala programs that use intervals and automatic differentiation, following ideas explored in the masters thesis of A. Danis (supervised by  W. Tucker). We now have scala programs that can enclose a function with the Taylor expansion (coefficients calculated using automatic differentiation) on intervals. The Lagrange error term is calculated on the whole interval. Here we see the function f(x) = (x^2+1)/(x^3-1) on the interval [3,4] enclosed with Taylor polynomials around 3 of degrees 1 (left figure) and  5 (right figure).


We also found out that due to the fact that we use a lazy datastructure to collect the derivatives of a function when doing automatic differentiation in Scala, we can turn an  initial value problem into the Taylor expansion of both the sought function and the field around the initial value.  This can be combined with tests to decide whether there is a solution around the initial point to approximate the solution in the next point.