MATLAB: Plotting 1/x correctly

functionplot

I'm trying to plot a simple function, 1/x. However it does not seem to work as intended. I define a linspace for my variable x and then use the plot() function.
As seen in the picture, for X=3, Y= 4.95. How is this possible? For X=3, Y should be equal to 0.33?
Is there something I'm missing causing the function to break the laws of mathematics? Changing the linspace size, or simply step size results in large differences as well.

Best Answer

Because you have not specified the x values in your plot, they run from 1 to the numel(s). So X is not an absolute value but the index into your x, defined as
x = linspace(0, 10, 100);
Then
x(3) = 0.2020
so y = 1/x = 4.95.
To get the right values, use
plot(x, 1./x)