Search code examples
matlabsymbolic-math

Factorize symbolic expression in quadratic form


Suppose I have in Matlab a symbolic equation like this

syms x y z real

T = 2*x^2 + k*y^2 + 6*k*x*y

How can I find the matrix B such that

T = [x y] * B * [x y]'

Thanks for your help.


Solution

  • Ok. I've just resolved this problem by myself.

    B = 0.5 * jacobian(jacobian(T,V),V)
    

    where V is a vector of variables.

    The explanation it's a bit mathematical. If you want more details just ask to me. :)