Home > calculus and analysis > Derivative from the left and right

Derivative from the left and right

June 4Hits:1
Advertisement

I am currently trying to write a script that takes a curve $C$, a starting point $p$ and a direction vector $\vec{v}$ and calculates the path of a beam starting at $p$ in direction $\vec{v}$ when it is reflected on $C$.

The idea is basically: (Numerically) find the (first) crossing point of beam and $C$, calculate tangent in that point, calculate new beam direction, repeat.

Now, if my curve is point-wise not differentiable (in my case: $C$ has "kinks"), I would like to treat it as a limit case where both smooth curves around the kinks are considered, so the calculation forks and I get 2 possible beam pathes. For this, I need the left and the right side derivative of this point. How do I get those in Mathematica?

Also, if somebody knows a better way or this has already been written and is public, I appreciate any clues, of course.

Answers

The NumericalCalculus Package already treats this:

Use Scale to specify directional derivatives.

Needs["NumericalCalculus`"]
f[x_] := TriangleWave[x];
ND[f[x], {x, 1}, 3/4, Scale -> -1]
ND[f[x], {x, 1}, 3/4, Scale -> 1]
(*
-> -3.99999
    3.99999
*)

If your kinked curve is a function that is known to Mathematica or is entirely in terms of functions known to Mathematica, you can go back to using the definition of left and right derivatives, and use Limit[] for the purpose, along with its Direction option:

Plot[TriangleWave[x], {x, 0, 2},
     Epilog -> {AbsolutePointSize[5], Point[{1/4, TriangleWave[1/4]}]}]

Derivative from the left and right

(* coming from the left *)
Limit[(TriangleWave[1/4 + h] - TriangleWave[1/4])/h, h -> 0, Direction -> 1]
4

(* coming from the right *)
Limit[(TriangleWave[1/4 + h] - TriangleWave[1/4])/h, h -> 0, Direction -> -1]
-4

If your function is an InterpolatingFunction[] or some other black-box function that can only take numerical arguments, different approaches are needed. If that's what you're interested in, I'll edit this answer later for a possible strategy for those.

Related Articles

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.422 s.