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

조회 수: 4 (최근 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.

답변 (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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by