Is the following way differentiating $x^TAx$ correct

139 Views Asked by At

I know that there are a lot of question where the differential is found. Before i checked out those answered i tried myself, and i can't quite figure out if the results are the same. Here is what i tried.

We have the following $$ \begin{array}{c}{f(x)=x^{T} A x} \\ {x=\left(\begin{array}{c}{x_{1}} \\ {\vdots} \\ {x_{n}}\end{array}\right) \quad \text { , } A=\left[\begin{array}{ccc}{a_{11}} & {\dots} & {a_{1 n}} \\ {\vdots} & {\ddots} & {\vdots} \\ {a_{n 1}} & {\dots} & {a_{n n}}\end{array}\right]}\end{array} $$

Find $$\frac{\partial f(x)}{\partial x_i}$$ This can be rewritten in the following way $$ f(x)=\sum_{k=1}^{n} \sum_{r=1}^{n} a_{r k} \cdot x_{r} \cdot x_{k} $$

We can divide this into the following cases $$ \left\{\begin{array}{ll}{x_{k} \cdot \sum_{r=1}^{n}\left(x_{k} \cdot a_{r k}\right)=\sum_{r=1}^{n} a_{r k} \cdot x_{k}^{2}} & {\text { for } k=i} \\ {x_{k} \cdot \sum_{r=1}^{n}\left(x_{k} \cdot a_{r k}\right)=c_{k}} & {\text { for } k \neq i}\end{array}\right. $$

Since we have to find the partial with respect to $x_i$ and constants will disapear we have to find the parital derivative of the following, $$ \begin{array}{c}{f(x)=\sum_{r=1}^{n} a_{r i} \cdot x_{i}^{2}} \\ {f_{x_{i}}^{\prime}(x)=2 \cdot \sum_{r=1}^{n} a_{r i} \cdot x_{i}}\end{array} $$

Is this method correct, or am i making an error somewhere? I understand the way other answers on here solves it, but i dont see why this is wrong - if it is.

2

There are 2 best solutions below

0
On

Your equation $f(x)=\sum_{k=1}^{n} \sum_{r=1}^{n} a_{r k} \cdot x_{r} \cdot x_{k}$ is, of course, correct.

The partial derivative with respect to $x_i$ is, by the product rule, $\sum_{r=1}^{n} a_{r i} \cdot x_{r} +\sum_{r=1}^{n} a_{i k} \cdot x_{k}$.

So there is no need for any extra algebra!

0
On

It's less fiddly to use the Kronecker delta, if you know of it. By the product rule, $$\frac{\partial}{\partial x_i}(x_jx_k)=\delta_{ij}x_k+x_j\delta_{ik}.$$Contracting with $A_{jk}$ (in the special case where it's $x_i$-independent, as I assume was your intent),$$\frac{\partial}{\partial x_i}(x^TAx)=\delta_{ij}A_{jk}x_k+x_jA_{jk}\delta_{ik}=A_{ik}x_k+x_jA_{ji}=((A+A^T)x)_i.$$This may be rewritten, of course, as$$\nabla_x(x^TAx)=(A+A^T)x.$$