How do I fill in a shape made by three lines?

5 views (last 30 days)
I'm trying to fill in a shape created by three lines: y=x^2; y=(-1/4)x+9/2; y=0. I still don't clearly understand the "fill" command and I can't find anything that would allow me to fill in this area. I could use some help and if you could explain what's going on and why.
As of right now, I've nothing in the fill section on my code, but I was instructed that it is supposed to come before the plot. This is my code so far:
%Supplement Problem 4
x=[0:0.5:20];
y=x.^2;
y2=x.*(-1./4)+(9./2);
y3=x.*0;
%Fill in the Shape
%Figure
plot(x,y,x,y2,x,y3); grid on;
axis([-1,20,-1,5])

Accepted Answer

Image Analyst
Image Analyst on 17 Oct 2015
Close. But try this:
%Supplement Problem 4
x=[0:0.5:20];
y=x.^2;
y2=x.*(-1./4)+(9./2);
y3=x.*0;
%Fill in the Shape
y4 = min([y;y2]);
%Figure
plot(x,y,x,y2,x,y3); grid on;
axis([-1,20,-1,5])
hold on;
area(x, y4, 'FaceColor', [0.7, 0.2, 0.8])

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!