How can I take the derivative of a symbolic matrix?

5 ビュー (過去 30 日間)
Benjamin Schuessler
Benjamin Schuessler 2018 年 1 月 7 日
編集済み: Benjamin Schuessler 2018 年 1 月 7 日
Hello, I'm having a little trouble taking the derivative of a symbolic matrix.
Let's say I have a symbolic matrix 'f':
f =
[ 1, 1, 1, 1, 1]
[ cos(x)^2 - 1, cos(x)^2 - 1, cos(x)^2 - 1, 1, 1]
[ (cos(x)^2 - 1)^2, (cos(x)^2 - 1)^2, (cos(x)^2 - 1)^2, cos(x)^2 - 1, 1]
How would I go about taking the derivative of each element, where the order of the derivative is the value of the exponent in the function (i.e f(1,1) exponent = 0 (no derivative) f(1,2) exponent = 1 (first deriv.) and f(1,3) exponent = 2 (second deriv.)?
Thanks in advance for any advice!
EDIT* I started out with:
a =
0 0 0 1 2
1 1 1 2 3
2 2 2 3 4
then using:
syms x
f = ((cos(x)^2)-1).^a
f =
[ 1, 1, 1, cos(x)^2 - 1, (cos(x)^2 - 1)^2]
[ cos(x)^2 - 1, cos(x)^2 - 1, cos(x)^2 - 1, (cos(x)^2 - 1)^2, (cos(x)^2 - 1)^3]
[ (cos(x)^2 - 1)^2, (cos(x)^2 - 1)^2, (cos(x)^2 - 1)^2, (cos(x)^2 - 1)^3, (cos(x)^2 - 1)^4]
Trying this equation df = diff(f,(a(i,j))) results in:
The second argument must be a variable or a nonnegative integer specifying the number of differentiations.

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 7 日
編集済み: Walter Roberson 2018 年 1 月 7 日
temp = arrayfun(@(colidx) diff(f(:,colidx), colidx-1), 1:size(f,2), 'uniform', 0);
result = [temp{:}];
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 7 日
f(1,2) = 1, and f(1,3) = 1, but you defined the two as having different derivatives, so we have to use the column number minus one as the order of the derivative.
You have not consistently defined the derivative order to be used. The two expressions cos(x)^2 - 1, (cos(x)^2 - 1)^2 both have a term to power 2, so one might say the order should be 2; on the other hand, if you expand out (cos(x)^2 - 1)^2 then you will have a cos(x)^4 so perhaps it should be order 4.
Benjamin Schuessler
Benjamin Schuessler 2018 年 1 月 7 日
編集済み: Benjamin Schuessler 2018 年 1 月 7 日
Thanks Walter for your help! I figured out my problem with a little modification to your original post.
I really appreciate it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by