berechnen sie in matlab x durch die multiplikation von f und den diagonalelementen von d in javascript

Here is the code to compute x by multiplying f and the diagonal elements of d in JavaScript:

index.tsx
// assuming f and d are already defined
var x = [];

// iterate over the diagonal elements of d and compute x
for (var i = 0; i < d.length; i++) {
    x[i] = f * d[i][i];
}
173 chars
8 lines

In MATLAB, the code would look like this:

main.m
% assuming f and d are already defined
x = f * diag(d);
56 chars
3 lines

The diag function in MATLAB returns a vector containing the diagonal elements of the input matrix d.

related categories

gistlibby LogSnag