Why is 0 and 30 1/2?
조회 수: 5 (최근 30일)
이전 댓글 표시
Trying to plot the function x[n] = u[n] - u[n-30]. I'm getting 1/2 for n=0 and n=30. The correct answer is 1 from 0-29 and 0>=30, right? Below is my code and the result. I've tried heaviside(sym(n)) - heaviside(sym(n-30)) and I get the same result (I don't really know the differnce between using sym and not).
댓글 수: 0
채택된 답변
Walter Roberson
2022년 5월 6일
heaviside(X) by default has a value of 1/2 when X has a value of 0
The Heaviside function does not have a well-defined value at 0 exactly. There are at least three different values for Heaviside(0) that are useful in practice: 0, 1, and 1/2 . When you reach 30, then has the value "not yet jumped", or has it "already jumped", or is in "in the process of jumping" ? Is the glass half-full or is it half-empty ?
You can use sympref('HeavisideAtOrigin') to change the value that heaviside(0) will return.
댓글 수: 4
Walter Roberson
2022년 5월 6일
sympref("HeavisideAtOrigin", 1)
n = 0:30;
xn = heaviside(n) - heaviside(n-30);
stem(n, xn)
Walter Roberson
2022년 5월 6일
If you get an error with
sympref('HeavisideAtOrigin', 1)
then you might possibly be using a version of MATLAB before R2015a.
추가 답변 (1개)
David Goodmanson
2022년 5월 6일
Hi Alexander;
This occurs because
heaviside(-.3:.1:.3)
ans = 0 0 0 0.5000 1.0000 1.0000 1.0000
The value of this function at 0 equals 1/2, not 0 or 1.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Mathematical Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!