Group Abstract Group Abstract

Message Boards Message Boards

Derivative wrt to a vector?

Posted 9 years ago

Hello,

I'm looking to take the derivative of the following function:

a = -mu/r^3 rvec

with respect to rvec. Where rvec is in R3 and r is the norm of rvec. I know the solution is

mu/r^3 [3 rhat rhat^T - I ]

where rhat is the unit vector of rvec, ^T is the transpose and I is a 3x3 identity matrix. How would I do this using mathematica though? Thanks in advance!

POSTED BY: Jeroen Geeraert
7 Replies
Posted 9 years ago

Do you refer to the the Jacobian matrix of a function f:R^n->R^m? In this case you can program this code for an arbitrary function:

J[fct_List, var_List] := 
 Module[{m, n}, m = Length[fct]; n = Length[var];
  Simplify[Table[D[fct[[i]], var[[j]]], {i, 1, m}, {j, 1, n}]]]

In the case of your function a(x,y,z) you define it as follows:

r:={x, y, z};
a:=-my r/(r.r)^(3/2);

An then you simply enter

J[a,r]
POSTED BY: Ulrich Utiger

You could try the following

rvec = {r1, r2, r3};

a = -my /Sqrt[rvec.rvec]^3  rvec

res1= D[a, {rvec}]

res1 // Together // MatrixForm

Now for your 2nd line ( rhat rhat^T is formed by the Outer-construct)

rhat = rvec/Sqrt[rvec.rvec]

res2 = my /Sqrt[rvec.rvec]^3  (3 Outer[Times, rhat, rhat] -  IdentityMatrix[3]) // FullSimplify

res2 // MatrixForm

res1 - res2 // Simplify
POSTED BY: Hans Dolhaine

Hi Hans,

Thanks for your response, this is what I was looking for. Now to take it one step further. Is it possible to get res1 into the following matrix form mu/r^3 [3 rhat rhat^T - I ] from components? This is of course the solution, and normally that wouldn't be known beforehand.

POSTED BY: Jeroen Geeraert
POSTED BY: Hans Dolhaine
POSTED BY: Jeroen Geeraert
POSTED BY: Hans Dolhaine

As far as I know Mathematica does not have this functionality readily built-in. But you can program these definitions from e.g. https://en.wikipedia.org/wiki/Matrix_calculus

For example, the operators Del does not have a built-in meaning, but you can add one yourself.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard