function cost = J9(B)

% computes cost for vector B which contains
% [b0,b1,b2,b3]

x = [1,2, 3, 4, 5, 6, 7, 8, 9, 10];
y = [18, 5, 17, 38, 40, 106, 188, 234, 344, 484];

b0 = B(1);
b1 = B(2);
b2 = B(3);
b3 = B(4);

yhat = zeros(1,10);
for i=1:10
    yhat(i) = b0 + b1*x(i) + ...
        b2*x(i)*x(i) + b3*x(i)*x(i)*x(i);
end

cost = sum((yhat-y).^2);

end