TaylorExpansionPlot.ml

(* Copyright INRIA and Microsoft Corporation, 2008-2013. *)
(* DDMF is distributed under CeCILL-B license. *)

INCLUDE "preamble.ml"

let_service TaylorExpansionPlotSVG
  (rep : any maple)
  (var : name maple)
  (min : any maple)
  (max : any maple)
  (order : int) :
  DynaMoW.Services.svg * unit =

  (* HACK: We need a call to series with a sufficiently large third argument *)
  (* to avoid a division by zero error in series. *)
  <:unit< series($(rep), $(var), $(int:order) + 1) : >> ;
  let plotfcn, range =
    Plot.plot_and_range << unapply($(rep), $(var)) >> min max in
  let plotfcn' = << plots[display]($(plotfcn), thickness=3) >> in
  let plotseries =
    <<
      plot({seq(convert(series($(rep), $(var), i), polynom),
                i=0..$(int:order))},
           $(var) = $(min) .. $(max), numpoints = 200)
    >> in
  <:unit< series($(rep), $(var)) ; >> ;
  let p =
    <<
      plots[display]([$(plotfcn'), $(plotseries)],
                     view=$(range)[2] )
    >> in
  (<:string< DynaMoW:-PlotToSVG($(p), $(range)) >>, ())

let title (rep, _) =
  <:text<plot of Taylor approximations of <:isymb<$(rep)>>>>

let_service TaylorExpansionPlot
  (rep : any maple)
  (var : name maple)
  (min : string = Constants.default_plot_min_abs)
  (max : string = Constants.default_plot_max_abs) :
  DC.sec_entities * unit with { title = title } =
  let plot =
    DC.plot
      (TaylorExpansionPlotSVG.descr
        (rep, var, Maple.evaluator_symbolic min,
         Maple.evaluator_symbolic max, 10)
        None) in
  <:par<
    Approximations by successive truncations of the Taylor series: $(plot)
  >>, ()

Generated by GNU Enscript 1.6.5.90.