G
greenflame
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(rows,cols) {
output = new Array(rows);
for (i=0;i<rows;i++) {
output = new Array(cols);
}
return output;
}
function copy2darr(input) {
output = create2darr(input.length,input[0].length);
for (i=0;i<input.length;i++) {
for (j=0;j<input[0].length;j++) {
output[j] = input[j];
}
}
return output;
}
function xrow(input,row,factor) {
output = copy2darr(input);
for (i=0;output[row-1].length;i++) {
output[row-1] *= 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(rows,cols) {
output = new Array(rows);
for (i=0;i<rows;i++) {
output = new Array(cols);
}
return output;
}
function copy2darr(input) {
output = create2darr(input.length,input[0].length);
for (i=0;i<input.length;i++) {
for (j=0;j<input[0].length;j++) {
output[j] = input[j];
}
}
return output;
}
function xrow(input,row,factor) {
output = copy2darr(input);
for (i=0;output[row-1].length;i++) {
output[row-1] *= factor;
}
return output;
}