why computeCost function shows incorrect dimension error in second call?
1 次查看(过去 30 天)
显示 更早的评论
h = X * theta;
sq_error = (h - y) .^ 2;
J = 1/(2*m) * sum(sq_error);
correcting the code with error message shows error in first call too.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/357844/image.png)
0 个评论
回答(1 个)
Hritika Suneja
2020-12-31
编辑:Hritika Suneja
2021-1-4
As the error suggests , the dimensions of the matrix being multiplied might not be consistent. In order to multiply 2 matrix the number of columns in the first matrix should match the number of rows in the second matrix. This condition might not be getting satisfied in your code and hence this error occurs.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!