take the derivative of x'*p*x where x is a vector and p is a matrix in matlab

To take the derivative of x'px, where x is a vector and p is a matrix, in Matlab, you can use the symbolic math toolbox. Here's an example of how it can be done:

main.m
syms x1 x2 x3                     % Define symbolic variables for x
x = [x1; x2; x3];                 % Create the vector x

syms p1 p2 p3 p4 p5 p6 p7 p8 p9    % Define symbolic variables for p
p = [p1 p2 p3; p4 p5 p6; p7 p8 p9]; % Create the matrix p

f = x'*p*x;                       % Define the function f(x) = x'*p*x

gradient(f, x)                    % Calculate the gradient of f with respect to x
406 chars
10 lines

The output of the above code will give you the derivative of x'px with respect to x, which is a vector.

gistlibby LogSnag