1
$\begingroup$

How to correctly differentiate quadratic form by vector in Mathematica, i.e.:

$Q=\omega^T I_{p} \omega$

$\frac{dQ}{d\omega}= ??? $

Clear["Derivative"];

ClearAll["Global`*"];

Q = Transpose[\[CapitalOmega]].Ip.\[CapitalOmega];

D[Q, \[CapitalOmega]];
$\endgroup$

1 Answer 1

3
$\begingroup$

There is no concept of "transposed vector" in Mathematica.

To illustrate, let's give your variables concrete values:

Ip = {{Ixx, Ixy, Ixz}, {Ixy, Iyy, Iyz}, {Ixz, Iyz, Izz}};
ω = {ωx, ωy, ωz};

Your $Q$ is simply

Q = ω . Ip . ω // Expand

(*    Ixx ωx^2 + 2 Ixy ωx ωy + Iyy ωy^2 + 2 Ixz ωx ωz + 2 Iyz ωy ωz + Izz ωz^2    *)

and its gradient with respect to $\omega$ is $\nabla_{\omega}Q=2I_p\cdot\omega$:

D[Q, {ω}] == 2 Ip . ω // Expand
(*    True    *)
$\endgroup$
6
  • $\begingroup$ Thank you for your answer. Is it possible to get this result without writing matrices and vectors into components? I will work with Lagrangians, which have many kinetic components, and the moments of inertia depend on generalized coordinates. It would be desirable to have the resulting equations of motion in matrix-vector form. $\endgroup$
    – ayr
    Commented Jul 7, 2021 at 18:44
  • 1
    $\begingroup$ Possibly. Please clarify your question with this new information. $\endgroup$
    – Roman
    Commented Jul 7, 2021 at 19:20
  • 1
    $\begingroup$ I've had much success using @CarlWoll's MatrixD package for similar tasks -- mathematica.stackexchange.com/questions/138708/… $\endgroup$ Commented Jul 7, 2021 at 23:18
  • 1
    $\begingroup$ There's also this package for differentiating. More general than Carl Woll's package, but also harder to use, see example github.com/ssmit1986/DualNumbers/issues/1 $\endgroup$ Commented Jul 7, 2021 at 23:18
  • $\begingroup$ @Roman Show in symbolic form what happens if $I_p$ depends on parameter $\theta$, i.e. $I_p(\theta)$ and $\omega(t)$, and find $\frac{d}{dt}(\frac{dQ}{d\omega})-\frac{dQ}{d\omega}$ $\endgroup$
    – ayr
    Commented Jul 12, 2021 at 6:59

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.