Why is 0 and 30 1/2?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexander Bearon
am 6 Mai 2022
Kommentiert: Walter Roberson
am 6 Mai 2022
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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 6 Mai 2022
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 Kommentare
Walter Roberson
am 6 Mai 2022
sympref("HeavisideAtOrigin", 1)
n = 0:30;
xn = heaviside(n) - heaviside(n-30);
stem(n, xn)
Walter Roberson
am 6 Mai 2022
If you get an error with
sympref('HeavisideAtOrigin', 1)
then you might possibly be using a version of MATLAB before R2015a.
Weitere Antworten (1)
David Goodmanson
am 6 Mai 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Mathematical Functions finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!