4

With Mathematica 10, I can nicely plot:

y = x^2 - 4 Abs[x] - x

But I have not been able to use ArcLength to get the length of portions of the curve.

I have an old Derive 6 math program that both plots and gets the arc length of the equation very nicely.

Why not with Mathematica?

Artes
  • 57,212
  • 12
  • 157
  • 245

4 Answers4

6

Mathematica does not know how to take the derivative of Abs[x]

D[Abs[x], x]

Derivative[1][Abs][x]

Consequently, use the equivalent (for real x) Sqrt[x^2]

Abs[x] == Sqrt[x^2] // Simplify[#, Element[x, Reals]] &

True

f[x_] = x^2 - 4 Sqrt[x^2] - x;

ArcLength[{x, f[x]}, {x, 0, 5}]

1/2 (5 Sqrt[26] + ArcSinh[5])

% // N

13.9038

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
5

One way to get the real-number version of Abs, which is piecewise differentiable is to use ComplexExpand:

ArcLength[ComplexExpand@{x, x^2 - 4 Abs[x] - x}, {x, 0, 5}]
(*  1/2 (5 Sqrt[26] + ArcSinh[5])  *)

Alternatively, PiecewiseExpand, along with the assumption that x is real works, too:

Assuming[x ∈ Reals,
 ArcLength[{x, PiecewiseExpand[x^2 - 4 Abs[x] - x]}, {x, 0, 5}]
 ]
(*  1/2 (5 Sqrt[26] + ArcSinh[5])  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • @MichaelE2...I do not know why but I always seem to forget this! +1 :) – ubpdqn Apr 08 '15 at 12:00
  • @ubpdqn Thanks. Your remark about "the consistent and problematic Abs[x]" makes me think there may be a duplicate. In fact I think I once answered in terms of Piecewise like you did and someone else used ComplexExpand. Lots of related questions - probably won't have time to sort through them all. – Michael E2 Apr 08 '15 at 12:21
3

Rather uninspiringly but consistent with problematic Abs[x]:

f[x_] := Piecewise[{{x^2 + 3 x, x < 0}, {x^2 - 5 x, x > 0}}]

e.g.

ArcLength[f[x], {x, -2, 2}]
ArcLength[f[x], {x, 0, 2}]
ArcLength[f[x], {x, -2, 0}]

yield respectively,

1/4 (3 Sqrt[10] + 5 Sqrt[26] + ArcSinh[3] + ArcSinh[5])
1/4 (-Sqrt[2] + 5 Sqrt[26] - ArcSinh[1] + ArcSinh[5])
1/4 (Sqrt[2] + 3 Sqrt[10] + ArcSinh[1] + ArcSinh[3])

For fun:

Column[{Plot[f[x], {x, -2, 2}, PlotLabel -> f[x], ImageSize -> 400],
  Plot[ArcLength[f[s], {s, -2, u}], {u, -2, 2}, PlotStyle -> Red, 
   PlotLabel -> ArcLength[f[x], {x, -2, s}], ImageSize -> 400]}, 
 Frame -> All]

enter image description here

ubpdqn
  • 60,617
  • 3
  • 59
  • 148
2

Since Abs behaves badly in some situations, let's first assume you want the arc length for some x>0. When x>0, your function can be rewritten as (I'll keep that un-simplified form so that you see, I only removed the Abs)

f[x_] := x^2 - 4 x - x

Now we can calculate the arc length for the interval [0,5] with the usual formula manually

Integrate[Sqrt[1+f'[x]^2],{x,0,5}]
(* 1/2 (5 Sqrt[26]+ArcSinh[5]) *)

If you want to use ArcLength, you just have to note that you need to put it into a parametric form

ArcLength[{x, f[x]}, {x, 0, 5}]
(* 1/2 (5 Sqrt[26] + ArcSinh[5]) *)
halirutan
  • 112,764
  • 7
  • 263
  • 474