I am trying to use the lusolve
function from mathjs 3.8.0 to solve a linear system. However, I have some trouble interpreting the returned result with respect to the input.
I will explain based upon the example from the docs: The example sources begin
var m = [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 3, 0], [0, 0, 0, 4]]; var x = math.lusolve(m, [-1, -1, -1, -1]); // x = [[-1], [-0.5], [-1/3], [-0.25]]
So far, so good - this represents the system
1a = -1
2b = -1
3c = -1
4d = -1
The solution is, obviously
a = -1
b = -0.5
c = -1/3
d = -0.25
as stated in the comment from the original example.
The actual return value is an array with the values in the same order as the input vectors, i.e. [[-1], [-0.5], [-1/3], [-0.25]]
.
However, now I try to switch to of the input vectors:
var m = [[1, 0, 0, 0], [0, 2, 0, 0], [0, 0, 0, 4], [0, 0, 3, 0]];
var x = math.lusolve(m, [-1, -1, -1, -1]);
I thought this should represent the system
1a = -1
2b = -1
3d = -1
4c = -1
If so, the solution should be
a = -1
b = -0.5
c = -0.25
d = -1/3
or [[-1], [-0.5], [-0.25], [-1/3]]
in JavaScript.
However, the actual return value of the function for this input is still [[-1],[-0.5],[-1/3],[-0.25]]
, like with the original input vector ordering.
Why is that? How does the ordering of returned coefficients match with the ordering of input vectors?