2D Plots
When plotting in Octave you plot points having their x-values stored in one vector and the y-values in another vector. The two vectors must be the same size.
You can use a x-vector to store the x-values; then you use element by element operations on the x-vector to store the function values in a y-vector. Having two vectors like this, you then use the command
plot(x_vector, y_vector)

>>> x=-2:2 x = -2 -1 0 1 2 >>> y=x.^2 y = 4 1 0 1 4 >>> plot(x,y)
Octave inserts lines between the points. If you want a smoother graph, make a longer x-vector.

>>> x=-2:0.5:2; >>> y=x.^2; >>> plot(x,y)
If you know how many points you want to plot in an interval, you can let Octave space the points linearly by using the command
linspace(first x-value, last x-value, number of evenly spaced points)

>>> x=linspace(-2, 2, 500); >>> y=x.^2; >>> plot(x,y)
by Malin Christersson under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License