Plotting the heaviside discontinuity function

13 Ansichten (letzte 30 Tage)
Aleem Andrew
Aleem Andrew am 13 Okt. 2020
Kommentiert: Aleem Andrew am 13 Okt. 2020
The plot generated by the following code is not always the same and sometimes somewhat inaccurate. For example, there should be a vertical line at x = 0 from y = 0 to y = 8 but the line sometimes has a slight slope and the y values don't always exactly match the correct values.
syms x
f = 8*heaviside(x) - 8*(heaviside(x).*x-heaviside(x-4).*(x-4).^1)+40*(heaviside(x-4).*(x-4).^0)-16*heaviside(x-6).*(x-6).^0;
fplot(f,[0 6])
How can one generate a precise plot rather than one that is based on approximations?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Okt. 2020
Start the plot slightly below 0 so as to give it a chance to see the full discontinuity at 0.
syms x
f = 8*heaviside(x) - 8*(heaviside(x).*x-heaviside(x-4).*(x-4).^1)+40*(heaviside(x-4).*(x-4).^0)-16*heaviside(x-6).*(x-6).^0;
xlim([-1, 7]); ylim([-5 20]); hold on
fplot(f,[-1 6])

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by