operator \: nonconformant arguments

问题:operator : nonconformant arguments (op1 is 2x2, op2 is 1x1)解决方法:
在这里插入图片描述错误原因: 写lr CostFunction的时候出错,导致矩阵维度不匹配。 主要就是你的就算过程有问题,你的函数可能写错了,所以需要慢慢的调试,比如说我最开始写的代码:

function [jVal, gradient] = costFunction(theta)
  jVal = (theta(1)-5) ^ 2 +(theta(2)-5)^2;
  gradient = zeros(2,1);
  gradient(1) = 2*(theta(1)-5); % gradient应该添加(1),否则不知道是哪个gradient
  gradient(2) = 2*(theta(2)-5);
  % 添加了(1)、(2),结果就正确了

改正之后的结果:

octave:8> [opttheta, functionVal,exitFlag] = fminunc(@costFunction, initialtheta, options)
opttheta =

   5
   5

functionVal = 7.8886e-31
exitFlag = 1

你可能感兴趣的:(Error,Correction,线性代数,机器学习)