4
$\begingroup$

I am trying to find the arc length for

enter image description here

using

n = 2; f[x_] := -2 Re[ExpIntegralEi[(ZetaZero[n]) Log[x]]] Log[x]/ Sqrt[x]
a = Quiet[FindMinimum[f[x], {x, 1.4}]];
b = Quiet[FindMaximum[f[x], {x, 1.7}]];
Plot[f[x], {x, (x /. a[[2]]) - 0.1, (x /. b[[2]]) + 0.1}, 
Epilog -> {Red, PointSize[Medium], Point[{{x /. a[[2]], a[[1]]},
{x /. b[[2]], b[[1]]}}]}, ImageSize -> 300]

arc = NIntegrate[ Sqrt[1 + D[f[x], x]^2], {x, (x /. a[[2]]), (x /. b[[2]])}]

Am I doing something silly?

$\endgroup$
  • 1
    $\begingroup$ Maybe ArcLength $\endgroup$ – Apple Sep 15 '14 at 15:06
  • $\begingroup$ @Chenminqi, I Googled "Mathematica arc length" but only ArcLengthFactor came up!! :/ $\endgroup$ – martin Sep 15 '14 at 15:10
  • $\begingroup$ FYI ArcLength: Introduced in 2014 (10.0) $\endgroup$ – george2079 Sep 15 '14 at 15:45
  • 2
    $\begingroup$ If you define f sans Re[], and then use Re[] on the max, min, plot, and NIntegrate, they will all work. As it stands, D has trouble with the Re because it is not an analytic function. $\endgroup$ – Daniel Lichtblau Sep 15 '14 at 18:38
  • 1
    $\begingroup$ Strongly related Wolfram Community thread: "Computing arch length of a spline curve." $\endgroup$ – Alexey Popkov Oct 28 '14 at 19:26
5
$\begingroup$

Based on @RunnyKine's comment the trouble is with Re. It seems there should be a more elegant way to do this, but moving the Re outside the differential does the job:

 da[x_] = Sqrt[1 +
     (Re@D[(-2 (ExpIntegralEi[(ZetaZero[n]) Log[x]]) Log[x]/Sqrt[x]),x])^2  ]
 NIntegrate[da[x], {x, x /. a[[2]], x /. b[[2]]}]

.308277

Also, yet another line measure approach:

 Total[Norm /@ 
     Differences@
          Table[{x, f[x]}, {x, (x /. a[[2]]), (x /. b[[2]]), .0001}]]

0.308216

$\endgroup$
  • $\begingroup$ Great - should have thought of that ! Thanks - should be a little more accurate :) $\endgroup$ – martin Sep 15 '14 at 16:54
4
$\begingroup$

If you just plot the region of the graph you're interested in:

pl = Plot[f[x], {x, (x /. a[[2]]), (x /. b[[2]])}, 
  Epilog -> {Red, PointSize[Medium], Point[{{x /. a[[2]], a[[1]]}, {x /. b[[2]], b[[1]]}}]}, 
  ImageSize -> 300, PlotPoints -> 500]

Mathematica graphics

Then, you can do:

ArcLength @ DiscretizeGraphics @ pl

0.30827679

$\endgroup$
  • $\begingroup$ great - thank you :) I searched for "Mathematica arc length" but only ArcLengthFactor came up! ... Any ideas why direct integration won't work? Am I missing something silly? $\endgroup$ – martin Sep 15 '14 at 15:09
  • 1
    $\begingroup$ @martin, let me look into that. $\endgroup$ – RunnyKine Sep 15 '14 at 15:12
  • 1
    $\begingroup$ @martin, if you evaluate D[f[x], x] by itself, you'll see where the problem is. You have a derivative of Re term left in there and I don't think Mathematica knows what to do with that. $\endgroup$ – RunnyKine Sep 15 '14 at 15:26
  • $\begingroup$ Ah great - OK, thanks! $\endgroup$ – martin Sep 15 '14 at 15:43
  • $\begingroup$ Cute, but how accurate is this? Does it just count pixels? If so, there are only two digits one can really trust. (I don't know what the OP is looking for, but I usually want more than two digits from my computations). $\endgroup$ – Igor Rivin Sep 15 '14 at 15:47
3
$\begingroup$

Or Create an interpolation function from the plot and calculate its arc length. Note that I have modified the definitions of a and b.

n = 2; f[x_] := -2 Re[ExpIntegralEi[(ZetaZero[n]) Log[x]]] Log[x]/Sqrt[x]
a = FindArgMin[f[x], {x, 1.4}][[1]] // Quiet;
b = FindArgMax[f[x], {x, 1.7}][[1]] // Quiet;

plt = Plot[f[x], {x, a, b}];

f2 = Interpolation[
   Cases[plt, Line[pts_] :> pts, Infinity][[1]]];

arc = NIntegrate[Sqrt[1 + f2'[x]^2], {x, a, b}]

0.308277

$\endgroup$
  • $\begingroup$ Thanks for the solution - will give it a go in a bit :) $\endgroup$ – martin Sep 15 '14 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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