1

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]];

dtn
  • 2,394
  • 2
  • 8
  • 18

1 Answers1

3

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    *)
Roman
  • 47,322
  • 2
  • 55
  • 121
  • 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. – dtn Jul 07 '21 at 18:44
  • 1
    Possibly. Please clarify your question with this new information. – Roman Jul 07 '21 at 19:20
  • 1
    I've had much success using @CarlWoll's MatrixD package for similar tasks -- https://mathematica.stackexchange.com/questions/138708/differentiating-functions-of-vectors-matrices/141237#141237 – Yaroslav Bulatov Jul 07 '21 at 23:18
  • 1
    There's also this package for differentiating. More general than Carl Woll's package, but also harder to use, see example https://github.com/ssmit1986/DualNumbers/issues/1 – Yaroslav Bulatov Jul 07 '21 at 23:18
  • @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}$ – dtn Jul 12 '21 at 06:59
  • @YaroslavBulatov MatrixD[Transpose[X].A.X, X] // TraditionalForm try this code with package, it seems to me, or is it working with an error? – dtn Jul 13 '21 at 06:07