# Length of a graph of a function

The question is as follows:

Calculate the length of the graph of the function $f(x)=e^x$ between $x=0$ and $x=1$.

Use this: $\alpha =\int_a^b \sqrt{\left(\frac{\partial f(x)}{\partial x}\right)^2+1} \, dx$

I made a graph to view:

f[x_] := E^x
Plot[f[x], {x, 0, 1}]


α = Integrate[Sqrt[D[f[x], {x}]^2 + 1], {x, 0, 1}]


$-\sqrt{2}+\sqrt{1+e^2}+\tanh ^{-1}\left(\sqrt{2}\right)-\tanh ^{-1}\left(\sqrt{1+e^2}\right)$

N[α]


$2.0035\, +0. i$

But this result I did not understand. Was it not supposed to return a real value?

• Mathematica automatically works with complex numbers, use Chop. 6884 – Kuba Dec 9 '16 at 10:47
• If you're not interested in the closed form, just use NIntegrate[] directly. Integrate[Sqrt[Exp[2 x] + 1], {x, 0, 1}] // TrigToExp // FullSimplify yields a result that does not give a spurious imaginary part after being treated with N[]. – J. M. will be back soon Dec 9 '16 at 16:44
• If you want the most direct WL approach, you could use: ArcLength[Exp[x], {x, 0, 1}]. – Carl Woll Dec 31 '16 at 10:34

f[x_] := E^x
a = Integrate[Sqrt[D[f[x], {x}]^2 + 1], {x, 0, 1}]


$-\sqrt{2}+\sqrt{1+e^2}+\tanh ^{-1}\left(\sqrt{2}\right)-\tanh ^{-1}\left(\sqrt{1+e^2}\right)$

The same is obtained with ArcLength[Exp[x], {x, 0, 1}].

N @ a


2.0035 + 0. I

The imaginary part is a numerical artifact; check, e.g.

N[a, 30]


2.00349711162735247856990275242 + 0.*10^-30 I

and

N[a, 50]


2.0034971116273524785699027524202391308211427952321 + 0.*10^-50 I

In fact, N[a, p] gives a result in the form real part + 0.*10^-p I for every p $-$ the imaginary part is a numerical zero due to working with inexact numbers.

The simplest thing to do is

N[a] // Chop


2.0035

or slightly more elaborate

TrigToExp[a] // N


2.0035

• ComplexExpand often helps with spurious real/imaginary parts. In this case, N@ComplexExpand@a also produces the real answer. – Carl Woll Dec 31 '16 at 10:32
• @CarlWoll ComplexExpand@a in this case gives the same as TrigToExp@a. – corey979 Dec 31 '16 at 11:52