# Why am I not getting a numeric response?

## Code

In[830]:= curvature[x_, y_, z_, t_] :=
With[{s = {x, y, z}},
With[{v = D[s, t]},
With[{ fT = v / Norm[v]},
With[{fK = D[fT, t] / Norm[v]},
Norm[fK]
]
]
]
]
curvature[ Cos[t], Sin[t], t, t] /. t -> 1 // N

Out[831]= \[Sqrt](0.5 Abs[-0.59501 -
0.0955129 (-0.909297 Derivative[1][Abs][0.540302] +
0.909297 Derivative[1][Abs][0.841471])]^2 +
0.5 Abs[-0.382051 +
0.148752 (-0.909297 Derivative[1][Abs][0.540302] +
0.909297 Derivative[1][Abs][0.841471])]^2 +
0.015625 Abs[-0.909297 Derivative[1][Abs][0.540302] +
0.909297 Derivative[1][Abs][0.841471]]^2)


## Question

I have a // N there.

Why do I not get a numerical answer. Instead, why do I have Derivative[1][Abs] all over the place?

Thanks!

## EDIT

The following "fixes" the code. Why?

myNorm[lst_] := Sqrt[lst . lst]
curvature[x_, y_, z_, t_] :=
With[{s = {x, y, z}},
With[{v = D[s, t]},
With[{ fT = v / myNorm[v]},
With[{fK = D[fT, t] / myNorm[v]},
myNorm[fK]
]
]
]
]
curvature[ Cos[t], Sin[t], t, t] /. t -> 1 // N


This returns 0.5

-
I like your tendency to make code immutable (nested With). You should really try my LetL macro (section "Examples of new scoping constructs / environments"), to reduce the boilerplate. With it, your code becomes curvature[x_, y_, z_, t_] := LetL[{s = {x, y, z}, v = D[s, t], fT = v/myNorm[v], fK = D[fT, t]/myNorm[v]}, myNorm[fK]]. For definitions made with SetDelayed, it expands at definition - time, so you do get a nested With in your function's definition. – Leonid Shifrin Jul 12 '12 at 13:47
@Leonid: Your mathematica.stackexchange.com answers read like chapters in a book. :-) – user1602 Jul 13 '12 at 4:22
Thanks :) They are in a sense, a future book which I hope to finish one day. – Leonid Shifrin Jul 13 '12 at 10:28

According to the chain rule of differentiation, $(f\circ g)'(t)=f'(g(t))g'(t)$. Look at:

D[Abs[Sin[t]], t]
(* Cos[t] Derivative[1][Abs][Sin[t]] *)


You have several Abs[Sin[t]] cropping up everywhere due to Norm[v] in your code.

I would suggest re-writing the function as:

Clear[curvature2]
curvature2[vec : {x_, y_, z_}, t_] :=
With[{norm = Simplify[Norm@#, t ∈ Reals] &},norm[D[#/norm@#, t]/norm@#] &@D[vec, t]]

curvature2[{Cos[t], Sin[t], t}, t]
(* 1/2 *)

-
Why are those not evaluated when I have already assigned t -> 1 ? – user1602 Jul 11 '12 at 5:11
Abs[Sin[x]] is not differentiable everywhere. So if you just give it a general form, it will happily differentiate Abs – R. M. Jul 11 '12 at 5:12
@RM: Interesting, so defining myNorm with sqrt fixes this. So basically, the core of the problem is that Mathematica's Norm uses abs? – user1602 Jul 11 '12 at 5:15
@term-rewritica What norm doesn't use Abs or some equivalent notion of length? – R. M. Jul 11 '12 at 5:17
@RM: why did square root of dot product "work" then? – user1602 Jul 11 '12 at 5:24