Plotting the heaviside discontinuity function

12 visualizaciones (últimos 30 días)
Aleem Andrew
Aleem Andrew el 13 de Oct. de 2020
Comentada: Aleem Andrew el 13 de Oct. de 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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Oct. de 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])

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by