2

I lost two days of trying to do this but with no result. How can I plot the quadratic equation's parabola and roots. Something like this. I just need to be able to see the parabola and that it crosses the abscissa at the write coordinates.

Here is what I have:

x = linspace(-50,50);
y = 1.*x.*x - 8.*x + 15;
plot(x,y)
hold on;
grid()

rts = roots([1,-8,15]);
plot(rts, zeros(size(rts)), 'o', "color", "r")

And the result is: enter image description here

As you can see, the top of the parabola at 0 ordinate, instead of under it. I will appreciate your help!

Christoph
  • 44,205
  • 8
  • 72
  • 163
user3132352
  • 403
  • 1
  • 7
  • 22

2 Answers2

2

Using a smaller linspace range works fine for me:

x = linspace(1,6);
y = 1.*x.*x - 8.*x + 15;
plot(x,y)
hold on;
grid()

rts = roots([1,-8,15]);
plot(rts, zeros(size(rts)), 'o', "color", "r")

enter image description here

Christoph
  • 44,205
  • 8
  • 72
  • 163
0

Christoph is right the plot could be misleading because a great linspace can flatten the part of the curve below the abscissa, and if you don't think and you make some error calculating the vertex, as I've done you are fried! This is another solution, I hope this one is right!

ezplot(@(x,y) x.^2 -x.*8 -y.+ 15)
hold on
grid on
rts = roots([1,-8,15]);
plot(rts,zeros(size(rts)),'o',"color","r");
line(xlim,[0 0], 'linestyle', '--')

enter image description here

G M
  • 14,123
  • 7
  • 67
  • 66