# Nothing appears in simple plot

I'm trying to get the following simple code to work. (The code is just supposed to graph the norm of the second derivative of a vector function).

z[t_] = {1, t^2, t^3}
Plot[D[D[Norm[z[t]], t], t], {t, 0, 5}]


Nothing appears on the graph, and I get errors like "General::ivar: ... is not a valid variable". I read that these errors can be avoided if one uses the Evaluate command:

Plot[Evaluate[D[D[Norm[z[t]], t], t]], {t, 0, 5}]


This code doesn't result in any errors, but nothing appears in the plot. Interestingly, the code that reverses the order of operations and graphs the second derivative of the norm works fine:

Plot[ Evaluate[Norm[D[D[z[t], t], t]]], {t, 0, 5}]


I tried using DiscretePlot as well, but that didn't help. What am I doing wrong? I suspect the problem somehow relates to evaluation, but I can't figure it out. Thanks in advance for any help!

You're running into two issues. We'll start with the one that is causing the messages.

By default Plot avoids symbolic evaluation of your function, and uses numeric evaluation instead. For example, it may evaluate at t=1.23:

D[D[z[1.23],1.23],1.23]


and then D complains that 1.23 isn't a valid variable and returns

D[D[{1, 1.5129, 1.8608669999999998}, 1.23], 1.23]


which is not a number that can be plotted. The solution for this is to wrap Evaluate around your entire function:

Plot[Evaluate[D[D[Norm[z[t]], t], t]], {t, 0, 5}]


Now when you evaluate it, there aren't any messages, but it's still an empty graphic. To understand why, we need to look at what

D[D[Norm[z[t]], t], t]


really is. If we evaluate it on it's own, we see that it's some complicated expression involving Abs'[t] and Abs''[t], and which again doesn't evaluate to plotable numbers when we put in t=1.23. This is because Norm[z[t]] is giving a solution that is appropriate for any number, including complexes:

Sqrt[1 + Abs[t]^4 + Abs[t]^6]


The simplest solution is to use Simplify to indicate that you only care about real-valued values of t:

Simplify[Norm[z[t]], Element[t, Reals]


which gives the expected (and nicely differentiable!):

Sqrt[1 + t^4 + t^6]


Including this back into our plot:

Plot[
Evaluate[D[D[Simplify[Norm[z[t]], Element[t, Reals]], t], t]],
{t, 0, 5}
]


we finally get the plot we're looking for: • Thanks a ton! That really helped. Apr 19, 2014 at 3:58

Here is a very simple, step-by-step way to go about solving your problem.

z[t_] := {1, t^2, t^3}
Norm[z[t]]

Sqrt[1 + Abs[t]^4 + Abs[t]^6]


Those absolute values are going to give us trouble, so lets get rid of them. You want to plot over the range 0 to 5, so we can assume t ≥ 0.

nz[t_] = Simplify[Norm[z[t]], Assumptions -> t >= 0]

Sqrt[1 + t^4 + t^6]


From the above, we can get a reasonable expression for the 2nd derivative.

ddnz[t_] = D[nz[t], {t, 2}]

(4 t^3 + 6 t^5)^2/(4 (1 + t^4 + t^6)^(3/2)) + (12 t^2 + 30 t^4)/(2 Sqrt[1 + t^4 + t^6])


Now the plot comes easily.

Plot[ddnz[t], {t, 0, 5}] 