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
With). You should really try myLetLmacro (section "Examples of new scoping constructs / environments"), to reduce the boilerplate. With it, your code becomescurvature[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 withSetDelayed, it expands at definition - time, so you do get a nestedWithin your function's definition. – Leonid Shifrin Jul 12 '12 at 13:47