(* sequence_limit.ml * * Author: W. M. Farmer * Revised: October 15, 2008 * * Description: The function seq_lim computes an approximation of * the limit of a sequence s : N -> R. In some cases, * if s does not have a limit, seq_lim may return a * bogus limit. *) let seq_lim s epsilon max_n = let abs x = if x >= 0. then x else (-. x) in let first = ref (s 0) in let second = ref (s 1) in let n = ref 1 in while (abs (!first -. !second) >= epsilon) && !n < max_n do first := !second ; second := s (!n + 1) ; n := !n + 1 done ; (!second, !n) ;;