MATLAB: How to plot y=-1/3*(x-​2)*(x-2.5)​*((x/2)-2.​75)*((x/5)​-3.25)*(x-​4)-1.45

MATLABplotplotting

Hi,
I'm trying to plot equation
The end product should look like this
I can do the rectangle and I can change the colors when needed to but I'm having trouble plotting the equation I showed.
What I'm trying right now is
X=0.1:4.1
Y=-1./3.*(x-2).*(x-2.5).*((x./2)-2.75).*((x./5)-3.25).*(x-4)-1.45
x1=1,y1=3
x2=1.5,y2=5
x3=2,y3=3
x4=1.5,y4=1
x5=1,y5=3
x=[x1 x2 x3 x4 x5]
y=[y1 y2 y3 y4 y5]
plot(x,y, X, Y)
What I'm getting with that is nothing like the one that I want.
Help is appreciated!

Best Answer

The range for ‘X’ is wrong.
Try this:
X=1.5:0.1:4.1;
Y=-1./3.*(X-2).*(X-2.5).*((X./2)-2.75).*((X./5)-3.25).*(X-4)-1.45;
The rest of the code is unchanged.