What is a symbolic expression (syms) and how do I use this when doing differentiation in matlab?
조회 수: 10 (최근 30일)
이전 댓글 표시
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!!!
댓글 수: 0
답변 (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)
dx = diff(X)
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)
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
So x is a symbolic variable. It contains no numerical value here.
y = x^3 + 3*x^2 - 2
diff(y,x)
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
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
Chunru
2021년 8월 29일
The function name is same for both symbolic and numerical:
a = rand(8, 1 )
b = diff(a)
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!