Derivative of a quadratic form

From Machinelearning

Let A∈Mn,n(R) be an n by n real-valued matrix, and let f:Rn→R be defined by f(x)=xTAx. On this page, we calculate the derivative of f.

Understanding the problem

Straightforward method

Using the definition of the derivative

The derivative is the linear transformation L such that:

limx→x0;x≠x0|f(x)−(f(x0)+L(x−x0))||x−x0|=0

Using our function, this is:

limx→x0;x≠x0|xTAx−x0TAx0−L(x−x0)||x−x0|=0

Defining h=x−x0, we have x=x0+h and

|(x0+h)TA(x0+h)−x0TAx0−L(h)||h|

Focusing on the subexpression (x0+h)TA(x0+h), since A is a matrix, it is a linear transformation, so we obtain (x0+h)T(Ax0+Ah). Since the transpose of a sum is the sum of the transposes, we have (x0T+hT)(Ax0+Ah). Now using linearity we have x0TAx0+hTAx0+x0TAh+hTAh.

Now the fraction is

|x0TAx0+hTAx0+x0TAh+hTAh−x0TAx0−L(h)||h|=|hTAx0+x0TAh+hTAh−L(h)||h|

Focusing on hTAx0, it is a real number so taking the transpose leaves it unchanged: hTAx0=(hTAx0)T=x0TATh.

Now the fraction is

|x0TATh+x0TAh+hTAh−L(h)||h|=|x0T(AT+A)h+hTAh−L(h)||h|

Using the chain rule