3
$\begingroup$

I have this piecewise continuous function which is also continuously differentiable over time :

psi[t_] := Piecewise[{{(1 + t)^3 (-3 t^2 + t), -1 <= t <= 0},
                      {(1 - t)^3 (3 t^2 + t), 0 <= t <= 1}}];

Now, for starters, when I Plot it, a discontinuity appears. This can easily be solved with a simple Exclusions -> None option in the Plotcommand.

But then, when I calculate its first derivative over time using D, I obtain the following:

D[psi[t], t]

Mathematica session

And then when I try to plot it :

plot of the function

  • Is there something wrong with my original psi[t_]function? (Is it not continuous for Mathematica?)
  • Why are the limits of definition of the first derivative modified?
  • Why is the first derivative discontinuous?

Now, the easy solution would be to construct the first derivative using the results proposed by the D function and re-defining the definition domain... But I really want to understand this issue (if there is one).

$\endgroup$
2
  • 1
    $\begingroup$ Try Plot[Evaluate[D[psi[t], t]], {t, -1, 1}] or Plot[D[psi[x], x] /. x -> t, {t, -1, 1}], or Plot[D[psi[t], t], {t, -1, 1}, Evaluated -> True]. $\endgroup$
    – kglr
    Commented Mar 11, 2013 at 22:03
  • $\begingroup$ Define $D[psi[t],t]$ to a funtion as $f[t _ ]=D[psi[t],t]$, then plot f[t]. It works! $\endgroup$ Commented Mar 7, 2019 at 9:36

3 Answers 3

6
$\begingroup$

One way to do this is to define the derivative function:

dPsi[t_] = D[psi[t], t]

which can then be plotted:

Plot[dPsi[t], {t, -3, 3}, PlotRange -> All]

The problem with your original formulation is that D[psi[t],t] does not evaluate to a function, it is instead d_t. The first derivative is not discontinuous, as a function, but it does have different definitions that correspond to the points where your Piecewise function changes.

$\endgroup$
8
$\begingroup$

Somewhat surprisingly, the easiest solution seems to have been overlooked:

Plot[psi'[t], {t, -3, 3}, PlotRange -> All]

As psi[t] has already been defined, it makes sense to use Derivative[] for producing the derivative.

$\endgroup$
2
$\begingroup$

I have solved this with a little hack:

Plot[D[psi[x], x] /. x->t, {t,-3, 3}].

This way I force Mathematica to first find the derivative and then substitute t into x and evaluate. However, this calculates the derivative for every t, so for more complex functions, it may become a performance issue.

$\endgroup$
1
  • 2
    $\begingroup$ Plot[D[psi[x], x], {x, -3, 3}, Evaluated -> True] will give the same plot and avoid recalculating D[psi[x], x] :-) $\endgroup$
    – Mr.Wizard
    Commented Jul 25, 2017 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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