How to shade area of Integral

21 views (last 30 days)
Pratik P
Pratik P on 24 Sep 2015
Commented: Star Strider on 25 Sep 2015
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!

Accepted Answer

Star Strider
Star Strider on 24 Sep 2015
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
  4 Comments
Pratik P
Pratik P on 25 Sep 2015
Exactly what I was trying to do. You sir are good thanks, I owe you a Coffey or beer what ever your flavor is.
Star Strider
Star Strider on 25 Sep 2015
My pleasure!
The sincerest expression of appreciation here on MATLAB Answers is what you have already done, that being your Accepting my Answer. If we ever meet, a coffee or beer together would be nice!

Sign in to comment.

More Answers (1)

WAT
WAT on 24 Sep 2015
It sounds like you want the area() function.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!