0

I am wanting to do a very simple plot of a polynomial using the plot(x,y) function. Here is my full code

a = linspace(-3, 0.1, 3);
plot(a, a.^3 - 3*a - 2);
ax = gca;
c = ax.Color;
grid on;

Which outputs the following picture

plot here

Why doesn't the graph extend from -3 to 3 on the x-axis? Why does it stop just after $0$?

Taln
  • 117
  • 5

1 Answers1

1

As the documentation states, in linspace(x1,x2,n) x1 is the begin value, x2 is the end value and n is the number of points. That's exacly what you see on your plot: 3 points: -3, 0.1 and one halfway (because of the linear spacing).

Since you want to have a particular spacing between your points, and not a certain number of points, I suggest you build your vector as:

a = -3:.1:3;
ViG
  • 1,848
  • 1
  • 11
  • 13