linsolve#
Purpose#
Solves \(Ax = b\) using the inverse function.
Format#
- x = linsolve(b, A)#
- Parameters:
b (NxK matrix) – data
A (NxN matrix) – data
- Returns:
x (NxK matrix) – the linear solution of \(b/A\) for each column in b.
Examples#
// Assign b
b = { 2, 3, 4 };
// Assign A
A = { 10 2 3, 6 14 2, 1 1 9 };
// Solve Ax = b
x = linsolve(b, A);
print x
0.04586330
0.13399281
0.42446043
Remarks#
linsolve()
solves for x by computing \(inv(A) \times b\). If A is square and b
contains more than 1 column, it is much faster to use linsolve()
than the
/
operator. However, while faster, there is some sacrifice in accuracy.
A test shows linsolve()
to be acccurate to within approximately 1.2e-11,
while the slash operator /
is accurate to within approximately 4e-13.
However, the accuracy sacrifice can be much greater for poorly
conditioned matrices.