0
$\begingroup$

How do I increase the number of decimal places for

f1 = Map[Flatten@*First]@MeshPrimitives[#, 1] &;
f2 = Flatten[Flatten[f1@CantorMesh[13]]];
f[x_] := x^(1/5)
N[Total[f@f2]/Length[f2], 10]

I get six decimal places instead of 10.

0.804028

How do we fix this?

$\endgroup$

1 Answer 1

4
$\begingroup$

We can write a new cantormesh function that uses exact numbers instead of floating-point approximations:

cantormesh[0] = {{0, 1}};
cantormesh[n_Integer?Positive] := cantormesh[n] = 
  Join @@ ({{#[[1]],(2#[[1]]+#[[2]])/3},{(#[[1]]+2#[[2]])/3,#[[2]]}} & /@
    cantormesh[n-1])

Now the result is exact:

f2 = Flatten[cantormesh[13]];
f[x_] = x^(1/5);
Z = Total[f@f2]/Length[f2]
(*    long output    *)

Ask for 30 digits:

N[Z, 30]
(*    0.804027503496689833535703631763    *)
$\endgroup$
1
  • 2
    $\begingroup$ Here is a nonrecursive version: cantormesh[n_Integer?NonNegative] := Nest[Replace[#, {x_?NumberQ, y_?NumberQ} :> Apply[Sequence, Partition[Subdivide[x, y, 3], 2]], 1] &, {{0, 1}}, n]. As for the OP's computation itself: With[{c = Flatten[N[cantormesh[13], 30]]}, Mean[c^(1/5)]]. $\endgroup$ Mar 30, 2020 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.