Sum of a series: Difference between revisions

Content deleted Content added
added ocaml
Line 173:
Alternatively, get Mathematica to do the whole calculation in floating point by using a floating point value in the formula:
Sum[1./x^2, {x, 1, 1000}]
 
=={{header|OCaml}}==
<ocaml>let sum a b fn =
let result = ref 0. in
for i = a to b do
result := !result +. fn i
done;
!result</ocaml>
 
# sum 1 1000 (fun x -> 1. /. (float x ** 2.))
- : float = 1.64393456668156124
 
=={{header|OpenEdge/Progress}}==
Line 200 ⟶ 211:
=={{header|Perl}}==
<perl>my $sum = 0;
map { $sum += 1 / ( $_ * $_ ) }foreach (1..1000);
print "$sum\n";
</perl>