MATLAB: How to calculate the first derivative of a vector with respect to a matrix

matrixvector

I have x = a*B*C, where x is 1*4 vector, a is 1*2 vector, B is 2*4 matrix, and C is 4*4 matrix.
How can I calculate the first derivative of the vector x with respect to matrix B?

Best Answer

syms a [1 2]
syms B [2 4]
syms C [4 4]
x = a*B*C;
derivs = arrayfun(@(X) reshape(gradient(X, B(:)),size(B)), x, 'uniform', 0);
Related Question