2
$\begingroup$

So I have problem for specific formula to create Quadratic_form form from $$y = 3 + x_1 - 2 x_4 + 2 x_3 x_4 + x_2 (-x_3 + x_4) $$ as matrix \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & -1/2 & 1/2 \\ 0 & -1/2 & 0 & 1 \\ 0 & 1/2 & 1 & -2 \end{bmatrix} We have in Mathematica special function for this?

$\endgroup$
  • $\begingroup$ I don't understand the relationship between the coefficients and the values in the matrix, so I can't help. The reference doesn't explain the form either. $\endgroup$ – mikado Oct 17 '19 at 20:19
  • $\begingroup$ @mikado of course, I fixed this issue. The representation of quadratic form as matrix, more is here: en.wikipedia.org/wiki/Quadratic_form $\endgroup$ – blabla Oct 17 '19 at 21:01
  • 4
    $\begingroup$ Suggest you look at CoefficientArray $\endgroup$ – mikado Oct 17 '19 at 22:08
  • 1
    $\begingroup$ Quoting the first line from the linked page, "In mathematics, a quadratic form is a polynomial with terms all of degree two." The example has terms not of degree two. So it needs to be made clear what exactly is wanted. $\endgroup$ – Daniel Lichtblau Oct 17 '19 at 22:24
  • 3
    $\begingroup$ Have a look at SolveAlways. $\endgroup$ – yarchik Oct 18 '19 at 15:09
5
$\begingroup$

If you want to determine a symmetric matrix $A$ such that if $x=(1,x_1,x_2,x_3,x_4)$ and

$$x^T A x = 3 + x_1 - 2 x_4 + 2 x_3 x_4 + x_2 (-x_3 + x_4)$$

then the following (based on the comment by @yarchik) should do that:

(* Create a symbolic symmetric matrix *)
A = Table[a[Min[i, j], Max[i, j]], {i, 0, 4}, {j, 0, 4}];

(* Quadratic form *)
y = 3 + x1 - 2 x4 + 2 x3 x4 + x2 (-x3 + x4)

(* Solve for the values of the symmetric matrix *)
x = {1, x1, x2, x3, x4};
(A = A /. SolveAlways[x.A.x == y, {x1, x2, x3, x4}][[1]]) // MatrixForm

$$\left( \begin{array}{ccccc} 3 & \frac{1}{2} & 0 & 0 & -1 \\ \frac{1}{2} & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & -\frac{1}{2} & \frac{1}{2} \\ 0 & 0 & -\frac{1}{2} & 0 & 1 \\ -1 & 0 & \frac{1}{2} & 1 & 0 \\ \end{array} \right)$$

As a check...

x.A.x // Simplify
(* 3 + x1 - 2 x4 + 2 x3 x4 + x2 (-x3 + x4) *)
| improve this answer | |
$\endgroup$

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