Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make a matrix out out of the following expression:

$$ (\Omega^2 (2 d\theta^2 + d\phi^2 - d\phi^2 \cos(2 \theta) \coth(\chi)^2) + (2 d\Omega^2 + (2 d\theta^2 + d\phi^2 - 2 d\chi^2) \Omega^2) \textrm{csch}(\chi)^2)/(2 \Omega^2) $$

so that I get for the 11-components all terms that belong to $d\Omega^2$, for the 22-component all the terms belonging to $d\chi^2$, etc. (As there are no 'cross-terms', the matrix in this case should be diagonal). How do I go about this in Mathematica?

Code for copying:

(Ω^2 (2 dθ^2 + dϕ^2 - dϕ^2 Cos[2 θ] Coth[χ]^2) +
 (2 dΩ^2 + (2 dθ^2 + dϕ^2 - 2 dχ^2) Ω^2) Csch[χ]^2)/(2 Ω^2)
share|improve this question
Please include the expression in Mathematica code for easy manipulation. Thanks – Mr.Wizard Aug 7 '13 at 13:58
Of course, here you go: ([CapitalOmega]^2 (2 d[Theta]^2 + d[Phi]^2 - d[Phi]^2 Cos[ 2 [Theta]] Coth[[Chi]]^2) + (2 d[CapitalOmega]^2 + (2 d\ [Theta]^2 + d[Phi]^2 - 2 d[Chi]^2) [CapitalOmega]^2) Csch[[Chi]]^2)/(2 \ [CapitalOmega]^2) – user25477 Aug 7 '13 at 14:11
You can edit your question to add such information. – Mr.Wizard Aug 7 '13 at 14:12

With the expression and the variables defined

expression =   1/(2 Ω^2) (Ω^2 (2 dθ^2 + dϕ^2 - dϕ^2 Cos[2 θ] Coth[χ]^2) +
              (2 dΩ^2 + (2 dθ^2 + dϕ^2 - 2 dχ^2) Ω^2) Csch[χ]^2);

differentials = {dχ, dθ, dϕ, dΩ};

You can get what you asked by calling

CoefficientArrays[expression, differentials][[3]] // Normal // MatrixForm
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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