3
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ myNorm'[{x_, y_, z_}] := Dt[myNorm[{x, y, z}], t]? $\endgroup$
    – wxffles
    Commented Sep 19, 2012 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$ Commented Sep 19, 2012 at 8:43

2 Answers 2

5
$\begingroup$

' or Derivative has the following attributes:

Attributes[Derivative]

{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];
??Derivative

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

$\endgroup$
3
$\begingroup$
myNorm[{x_, y_, z_}] := Sqrt[x^2 + y^2 + z^2];
Dt[myNorm[{x, y, z}], t]
$\endgroup$
5
  • $\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$ Commented Sep 19, 2012 at 2:05
  • $\begingroup$ In addition, I need to have MyNorm'[{x,y,z}] evaluate to Dt[myNorm[{x, y, z}], t]. $\endgroup$ Commented Sep 19, 2012 at 2:09
  • $\begingroup$ @Ben7005 Edit your question and add all the relevant info $\endgroup$ Commented Sep 19, 2012 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$ Commented Sep 19, 2012 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$ Commented Sep 19, 2012 at 2:49

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.