I have the following function. It is supposed to multiply all the
elements of a row of a matrix my a certain factor. I make a matrix with
a list of lists. with each of the inner lists represents a row of a
matrix. So the matrix:
[1 2 3]
[4 5 6]
[7 8 9]
is coded as:
A = [
[1,2,3],
[4,5,6],
[7,8,9]
];
OK now heres the function:
function create2darr(row s,cols) {
output = new Array(rows);
for (i=0;i<rows;i++ ) {
output[i] = new Array(cols);
}
return output;
}
function copy2darr(input ) {
output = create2darr(inp ut.length,input[0].length);
for (i=0;i<input.le ngth;i++) {
for (j=0;j<input[0].length;j++) {
output[i][j] = input[i][j];
}
}
return output;
}
function xrow(input,row, factor) {
output = copy2darr(input );
for (i=0;output[row-1].length;i++) {
output[row-1][i] *= factor;
}
return output;
}
elements of a row of a matrix my a certain factor. I make a matrix with
a list of lists. with each of the inner lists represents a row of a
matrix. So the matrix:
[1 2 3]
[4 5 6]
[7 8 9]
is coded as:
A = [
[1,2,3],
[4,5,6],
[7,8,9]
];
OK now heres the function:
function create2darr(row s,cols) {
output = new Array(rows);
for (i=0;i<rows;i++ ) {
output[i] = new Array(cols);
}
return output;
}
function copy2darr(input ) {
output = create2darr(inp ut.length,input[0].length);
for (i=0;i<input.le ngth;i++) {
for (j=0;j<input[0].length;j++) {
output[i][j] = input[i][j];
}
}
return output;
}
function xrow(input,row, factor) {
output = copy2darr(input );
for (i=0;output[row-1].length;i++) {
output[row-1][i] *= factor;
}
return output;
}
Comment