duanduanxi9441 2013-11-10 03:02
浏览 116
已采纳

意外的T_STRING错误(PHP)

I can normally catch these easy, but......

function linear_regression($x, $y) {

// calculate number points
$n = count($x);

// ensure both arrays of points are the same size
if ($n != count($y)) {

trigger_error("linear_regression(): Number of elements in coordinate arrays do not match.", E_USER_ERROR);

}

// calculate sums
$x_sum = array_sum($x);
$y_sum = array_sum($y);

$xx_sum = 0;
$xy_sum = 0;

for($i = 0; $i < $n; $i++) {

$xy_sum+=($x[$i]*$y[$i]);
$xx_sum+=($x[$i]*$x[$i]);

  }



  // calculate slope
  //$m = (($n * $xy_sum) - ($x_sum * $y_sum)) / (($n * $xx_sum) - ($x_sum * $x_sum));

  $divisor = (($n * $xx_sum) – ($x_sum * $x_sum));
if ($divisor == 0){
 $m = 0;
} else {
$m = (($n * $xy_sum) – ($x_sum * $y_sum)) / $divisor;
}


  // calculate intercept
  $b = ($y_sum - ($m * $x_sum)) / $n;

  // return result
  return array("m"=>$m, "b"=>$b);

}

var_dump( linear_regression(array(1, 2, 3, 4, 4), array(1.5, 1.6, 2.1, 3.0, 6)) );

The error is happening here $divisor = (($n * $xx_sum) – ($x_sum * $x_sum));

Any ideas why?

  • 写回答

4条回答 默认 最新

  • dongyou26216708 2013-11-10 03:13
    关注

    The minus sign is a fancy unicode dash (I think the em dash) instead of the regular ascii - character.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号