MATLAB: How to shade area of Integral

beershade

Hi I have a simple function y(z) = -1*z^3+4*z^2+-5*z+2 I have the integral in range of x= 0-5. I have the plot of the graph. I would like to shade this area on the graph.
What do I do? THANKS!

Best Answer

I’m not quite certain what you want. This shades the area between the x-axis and the value of the integral over the interval (0,5):
y = @(z) -1*z.^3+4*z.^2+-5*z+2;
x = linspace(0, 5);
inty = cumtrapz(x,y(x));
figure(1)
plot(x, inty, '-k', 'LineWidth',1)
hold on
patch([x fliplr(x)], [zeros(size(x)) fliplr(inty)], 'g')
hold off
grid