What is a symbolic expression (syms) and how do I use this when doing differentiation in matlab?
9 ビュー (過去 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 件のコメント
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!