Unit Step Funtion Without using heaviside function
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can I plot the u(t) = u(t-1)+u(t-2)+u(t-3)+u(t-4)-u(t+1)-u(t+2)-u(t+3)-u(t+4) ?
I would like to have the plot going up on both sides without using the heaviside func.
Thank you!
4 Kommentare
Sam Chak
am 21 Jun. 2022
I see. Thanks for your clarification. The general idea is to create a function that produce the same output like the Heaviside function. For example, let's create a SAM function (square and minus) 😄
sam = @(x) x.^2 - x;
A = sam(5)
Antworten (1)
Jonas
am 21 Jun. 2022
Bearbeitet: Jonas
am 21 Jun. 2022
you could go over the integration of the delta function, which is the heaviside function:
t=-5:5;
ds=[0 1 1 1 1 0 -1 -1 -1 -1 0];
s=cumsum(ds);
stairs(t,s)
edit: ok, i think ds needs to be multiplied with -1:
ds=[0 -1 -1 -1 -1 0 1 1 1 1 0];
2 Kommentare
Sam Chak
am 21 Jun. 2022
Yup, can't find any difference between them.
% Code directly using Heaviside function
t = linspace(-5, 5, 10001);
u = heaviside(t - 1) + heaviside(t - 2) + heaviside(t - 3) + heaviside(t - 4) - heaviside(t + 1) - heaviside(t + 2) - heaviside(t + 3) - heaviside(t + 4);
plot(t, u, 'linewidth', 1.5)
grid on
xlabel('t')
% Code indirectly depending on Heaviside function
A = gradient(u);
k = 1;
for j = 1:1000:10001
dS(k) = 2*A(j);
k = k + 1;
end
S = cumsum(dS); % integration of the delta function
T = -5:5;
stairs(T, S, 'r-', 'linewidth', 1.5)
grid on
xlabel('t')
Jonas
am 21 Jun. 2022
there may be no visual difference but the difference lies in the detail. Heaviside is defined as 0.5 at 0 and the cumsum version is already 1 there.
Siehe auch
Kategorien
Mehr zu Logical 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!