# Find arc length

I am trying to find the arc length for 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[]) - 0.1, (x /. b[]) + 0.1},
Epilog -> {Red, PointSize[Medium], Point[{{x /. a[], a[]},
{x /. b[], b[]}}]}, ImageSize -> 300]

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


Am I doing something silly?

• Maybe ArcLength – Apple Sep 15 '14 at 15:06
• @Chenminqi, I Googled "Mathematica arc length" but only ArcLengthFactor came up!! :/ – martin Sep 15 '14 at 15:10
• FYI ArcLength: Introduced in 2014 (10.0) – george2079 Sep 15 '14 at 15:45
• 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. – Daniel Lichtblau Sep 15 '14 at 18:38
• Strongly related Wolfram Community thread: "Computing arch length of a spline curve." – Alexey Popkov Oct 28 '14 at 19:26

## 3 Answers

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[], x /. b[]}]


.308277

Also, yet another line measure approach:

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


0.308216

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

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

pl = Plot[f[x], {x, (x /. a[]), (x /. b[])},
Epilog -> {Red, PointSize[Medium], Point[{{x /. a[], a[]}, {x /. b[], b[]}}]},
ImageSize -> 300, PlotPoints -> 500] Then, you can do:

ArcLength @ DiscretizeGraphics @ pl


0.30827679

• 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? – martin Sep 15 '14 at 15:09
• @martin, let me look into that. – RunnyKine Sep 15 '14 at 15:12
• @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. – RunnyKine Sep 15 '14 at 15:26
• Ah great - OK, thanks! – martin Sep 15 '14 at 15:43
• 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). – Igor Rivin Sep 15 '14 at 15:47

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}][] // Quiet;
b = FindArgMax[f[x], {x, 1.7}][] // Quiet;

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

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

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


0.308277

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