フィルターのクリア

How to perform the derivation of a symbolic vector on an symbolic function?

8 ビュー (過去 30 日間)
Chris B
Chris B 2018 年 3 月 26 日
コメント済み: Chris B 2018 年 5 月 23 日
Hello,
I would like to perform a derivation of a function containing symbolic vectors and matrices.
As an example:
a = sym('a', [3 3], 'real');
b = sym('b', [3 1], 'real');
c = sym('c', [3 1], 'real');
d = a*b + c
diff(d,c)
Here I get an error saying:
Error using sym/diff (line 70) Second argument must be a variable or a nonnegative integer specifying the number of differentiations.
The problem is that C is defined as:
c =
c1
c2
c3
And this way I cannot differentiate for c. I also tried to define separate symbols c1 c2 c3 but this does not work either.
  2 件のコメント
Christopher Creutzig
Christopher Creutzig 2018 年 3 月 27 日

Are you maybe looking for jacobian(a*b+c,c)?

Chris B
Chris B 2018 年 5 月 23 日
Yes that was it, tank you.

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

回答 (1 件)

Birdman
Birdman 2018 年 3 月 26 日
The error that you get actually tells you what to do: Variable d is not a function of variable c. You need to indicate that d(c) and then do the operations. For example, let's consider the possible approaches:
1- Your initial case:
a = sym('a', [3 3], 'real');
b = sym('b', [3 1], 'real');
c = sym('c', [3 1], 'real');
d = a*b + c
diff(d,c)
d is not dependent on any of those variables, therefore its change according to c will not mean anything, which will end up zero mathematically. This is normal.
2- d being dependent on c:
a = sym('a', [3 3], 'real');
b = sym('b', [3 1], 'real');
c = sym('c', [3 1], 'real');
d(c) = a*b + c
diff(d,c)
This will either not work because c contains three elements. You need to specify according to which element of c you are taking derivative. For instance:
>> diff(d,c(1))
ans(c1, c2, c3) =
1
0
0
>> diff(d,c(2))
ans(c1, c2, c3) =
0
1
0
Hope this helps.
  2 件のコメント
Christopher Creutzig
Christopher Creutzig 2018 年 3 月 27 日

The d(c) step is not needed. It's perfectly reasonable to call diff(a*b+c,c(1)).

Birdman
Birdman 2018 年 3 月 27 日
It is written to show how to define a function dependent on a variable symbolically. Of course, it can be eliminated.

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

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by