# What is a symbolic expression (syms) and how do I use this when doing differentiation in matlab?

조회 수: 2(최근 30일)
Victoria Helm 2021년 8월 28일
댓글: Walter Roberson 2021년 8월 29일
Hi I have some data with voltage spike recordings that I need to count. I want to use the diff() function to count the number of spikes (i.e. the number of rises and drops) that occur over a period of time. However, I am seeing that I need to use a symbolic expression for the thing that I am differentiating with respect to. Can someone explain to me what this means? Can I make an array of symbolic expressions? (For example, an array times that are of type syms)?
Thank you!!!

댓글을 달려면 로그인하십시오.

### 답변(2개)

John D'Errico 2021년 8월 29일
No. You misunderstand what diff does, and why diff is used there.
diff, when applied to a numeric vector, forms the difference between successive elements. This is NOT a derivative.
For example,
X = primes(20)
X = 1×8
2 3 5 7 11 13 17 19
dx = diff(X)
dx = 1×7
1 2 2 4 2 4 2
All it did was compute the difference between pairs of successive elements. We can get the same result by the operation:
dx_2 = X(2:end) - X(1:end-1)
dx_2 = 1×7
1 2 2 4 2 4 2
Again, this is NOT a derivative. Your confusion stems from the fact that diff can also be used to perform differentiation, when applied to a symbolic expression. And that is where syms comes in. For example:
syms x
whos x
Name Size Bytes Class Attributes x 1x1 8 sym
So x is a symbolic variable. It contains no numerical value here.
y = x^3 + 3*x^2 - 2
y = diff(y,x)
ans = As you can see, differentiation of an expression was performed. In both cases, a function named diff was used, but they do entirely different things, depending upon the input arguments.
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

Chunru 2021년 8월 29일
If you have numerical recordings instead of fumula/expressions for input, the should use numerical diff. "findpeaks" may be also helpful.
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
Walter Roberson 2021년 8월 29일
For numeric derivative estimation, typically using gradient() is a better choice.
Numeric differences can be estimated in several different ways. Forward differences; Backwards Differences; Central Differences; and others.

댓글을 달려면 로그인하십시오.

### Community Treasure Hunt

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

Start Hunting!