I am trying to make a function like Norm but defined like so: MyNorm[{x_,y_,z_}]=Sqrt[x^2+y^2+z^2]. Mathematica assumes that x, y, and z are constants, and gives MyNorm'[{x,y,z}] to be 0 for any x, y, or z. This would be fine, except that my x, y, and z will be functions of t, and I would like MyNorm'[{x,y,z}] to be equal to $$\frac{\mathrm d}{\mathrm dt} \mathtt{MyNorm[\{}x(t),y(t),z(t)\mathtt{\}]}$$

Does anyone know how to do this?

  • $\begingroup$ myNorm'[{x_, y_, z_}] := Dt[myNorm[{x, y, z}], t]? $\endgroup$ – wxffles Sep 19 '12 at 4:14
  • 1
    $\begingroup$ In the $\LaTeX$ example you have MyNorm with 3 arguments, but in the code definition is has a single, vector argument. What is it now? $\endgroup$ – Sjoerd C. de Vries Sep 19 '12 at 8:43

' or Derivative has the following attributes:


{NHoldAll, ReadProtected}

Conspicuously absent is the Protected attribute. This means that, unlike many other system functions, downvalues for Derivative can be defined directly.

In this case you seem to want this definition (as suggested by wxffles in comments):

MyNorm'[{x_, y_, z_}] := Dt[MyNorm[{x, y, z}], t]

The total derivative Dt is needed here to explicitly indicate that all variables depend on t.

Show it works:

MyNorm'[{x, y, z}]

(2 x Dt[x, t] + 2 y Dt[y, t] + 2 z Dt[z, t])/(2 Sqrt[ x^2 + y^2 + z^2])

If you clear the ReadProtected attribute you can see the definition is indeed assigned to Derivative:

ClearAttributes[Derivative, ReadProtected];

Mathematica graphics

Usually you would use TagSet or TagSetDelayed (/: = or /: :=) to associate this definition with MyNorm but in this case it would appear to deeply nested:

MyNorm /: MyNorm'[{x_, y_, z_}] := Dt[MyNorm[{x, y, z}], t]

Mathematica graphics

myNorm[{x_, y_, z_}] := Sqrt[x^2 + y^2 + z^2];
Dt[myNorm[{x, y, z}], t]
  • $\begingroup$ While this does give the derivative of the norm function, when I attempt deriving myNorm[r[t]] where r[t] is a piecewise parametric function in three parts {x[t], y[t], z[t]}, it still returns an error message. $\endgroup$ – diracdeltafunk Sep 19 '12 at 2:05
  • $\begingroup$ In addition, I need to have MyNorm'[{x,y,z}] evaluate to Dt[myNorm[{x, y, z}], t]. $\endgroup$ – diracdeltafunk Sep 19 '12 at 2:09
  • $\begingroup$ @Ben7005 Edit your question and add all the relevant info $\endgroup$ – Dr. belisarius Sep 19 '12 at 2:18
  • 1
    $\begingroup$ belisarius' answer strikes me as correct. If $x$, $y$, and $z$ are, in fact, functions (even in symbolic, as in x[t]), then this works fine. If they are not, then their derivatives should be zero. $\endgroup$ – Mark McClure Sep 19 '12 at 2:28
  • $\begingroup$ Yes but as I said above I need to have MyNorm'[{x,y,z}] evaluate to Dt[myNorm[{x, y, z}], t] $\endgroup$ – diracdeltafunk Sep 19 '12 at 2:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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