!! Submission failed: unexpected error: Error using computeCost Too many output arguments.
Show older comments
When I put this expression in MATlab I get:
!! Submission failed: unexpected error: Error using computeCost
Too many output arguments.
!! Please try again later.
function J = computeCost(X, y, theta)
data = load('ex1data1.txt');
m = 97;
X = [ones(m, 1), data(:,1)];
theta = zeros(2, 1);
h = X * theta;
y = data(:, 2);
error = h - y;
error_sqr = error.^2;
q = sum(error_sqr);
J = (1/ (2*m) * q)
3 Comments
Walter Roberson
on 15 Apr 2020
Why are you overwriting the input X and y and theta?
What is the point of setting theta to 0 and then multiplying by theta ?
How can you be certain that data will always have exactly 97 rows?
Martin Felipe Wohlgemuth Pinzon
on 15 Apr 2020
Walter Roberson
on 17 Apr 2020
function J = computeCost(X, y, theta)
That line tells you that X, y, and theta are normally expected to be passed in as inputs.
data = load('ex1data1.txt');
m = 97;
Neither of those lines read or write X, y, or theta, so the input X, y, theta do not matter to those two lines.
X = [ones(m, 1), data(:,1)];
theta = zeros(2, 1);
h = X * theta;
y = data(:, 2);
The first of those lines ignores any X that was passed in and overwrites X with values. The second discards theta that was passed in and overwrites theta with zeros. The fourth line discards y that was passed in and overwrites y with values.
Therefore no matter what was passed in for X, y, theta, the code will ignore them and do its own thing.
Answers (0)
Categories
Find more on Time Series Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!