-1

Is there a way to convert that? For example from this equation:

enter image description here

To this matrix form:

enter image description here

We especially would like to get thos matrices circled-red.

This is the code I have at the moment:

from sympy import *
x, y = symbols('x y')
expr = 0.5 * (x**2) + 3*x + 4*y
print(latex(expr))

I welcome suggestion other than Simpy (no MATLAB please).

At the end of the day I'd like to use it with CVXOPT or Scipy.

Stefan Scherfke
  • 3,012
  • 1
  • 19
  • 28
neversaint
  • 60,904
  • 137
  • 310
  • 477

1 Answers1

3

I can't give you any python code, but I can explain how to derive the matrices and the vector:

Your form is:

                     T                           T
f(x, y) = 1/2 * | x |  * | a  b | * | x | + | d |  * | x |
                | y |    | b  c |   | y |   | e |    | y |

This is equal to:

f(x, y) = 1/2 * a x^2 + b * xy + 1/2 * c y^2 + d x + e y

So you just need to put the coefficients at the correct positions in the matrix form (a = 2 * coefficient of x^2, b = coefficient of xy, etc.).

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70