简体   繁体   English

处理错误“语法错误; 但发现我”

[英]Processing error “Syntax error expected ; but found i”

I am trying to write a matrix library in processing using javascript but keep getting the error above on line 5. I can't seem to spot what is causing the error so any help would be appreciated. 我正在尝试使用javascript在处理中编写矩阵库,但始终在第5行出现错误。我似乎无法发现导致错误的原因,因此不胜感激。

The goal is to implement the matrix product function. 目标是实现矩阵乘积函数。

 function Matrix(rows,cols){ this.rows = rows; this.cols = cols; this.data = []; for(var i = 0; i < this.rows; i++){ //assign every row an array this.data[i] = []; for (var j = 0; j < this.cols; j++){ //assign every column an array this.data[i][j] = 0; } } } Matrix.prototype.multiply = function(n){ if(n instanceof Matrix){ // Matrix product if (this.cols !== n.rows) { console.log('Columns of A must match rows of B.'); return undefined; } let result = new Matrix(this.rows, n.cols); for (let i = 0; i < result.rows; i++) { for (let j = 0; j < result.cols; j++) { // Dot product of values in col let sum = 0; for (let k = 0; k < this.cols; k++) { sum += this.data[i][k] * n.data[k][j]; } result.data[i][j] = sum; } } return result; } else{ for(var i = 0; i < this.rows; i++){ for (var j = 0; j < this.cols; j++){ //multiply scalar this.data[i][j] *= n; } } } } 

我发现错误只是在错误的位置出现了花括号!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM