Given a bunch of data $x_i$ , $y_i$, how do I plot $$f(\theta_2,\theta_2)= \frac{1}{2M} \sum_{i=1}^{M} (\theta_1\cdot x_i -\theta_2 y_i)^2$$ in matlab? I know it should be parabolic, but my code (shown below) doesn't give me a parabaloid.
x=linspace(0,1,1001);
M=numel(x);
y=2*x-3+(-2+4*rand());
plot(x,y)
[theta1,theta2]=meshgrid(0:0.01:3,-5:0.01:-2);
J=zeros(length(theta1),length(theta2));
for i = 1:M
J=J+(theta1*x(i)-theta2-y(i)).^2;
end
J=(2*M)^(-1)*J;
mesh(theta1,theta2,J)
I changed the domain of theta1 and theta2 to
and I got the following parabaloid-looking plot: