Symbol matrix function differentiation

5 Ansichten (letzte 30 Tage)
chen xy
chen xy am 3 Mär. 2013
1.The function 'diff' seems could only work with one-element variable 'v',
diff(f,v); % f(v), v is a one-lelement variable
while I would like do differentiation on a symbol matrix
diff(F, V); % F(V), V is a symbol matrix variable
2.If I make differentiation to each element of the symbol matrix, and obtain the result of diff(F, V), while the result is in element by element format,
[g1(v_i), g2(v_i), ..., gn(v_i)]
so I want to know are there some methods to make the result in symbol matrix variable format like this?
g(V)
3.for example
diff(x^T*A*x, x) = A^T*x + A*x; % A is a constant matrix, x is a vector

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Mär. 2013
Bearbeitet: Walter Roberson am 4 Mär. 2013
If you want the result to be like in your (2) above, then use a "for" loop, or use
g = feval(symengine, 'zip', F, V, 'diff');
or use
g = cell2mat(arrayfun(@diff, F, V, 'Uniform', 0));
You might be able to just use
g = arrayfun(@diff, F, V);
but I think I recall seeing that have problems with arrayfun expecting numeric results.
  6 Kommentare
chen xy
chen xy am 5 Mär. 2013
If A isn't square, "x.'*A*x" will be wrong for matrix dimensions.
Walter Roberson
Walter Roberson am 5 Mär. 2013
True.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by