linsolve
Solves a linear system, optionally telling it about the matrix structure.
Category: Mathematics > Linear Algebra
Syntax
X = linsolve(A, B)
Solves A*X = B, like A\B.
X = linsolve(A, B, opts)
Uses the structure flags in the struct opts, such as UT, LT, SYM, POSDEF or TRANSA, to pick a faster method.
Description
When you know that A is triangular or symmetric positive definite, passing that fact in opts lets linsolve skip the general factorization. The flags are trusted, not checked: if the claim is false the answer is wrong.
For general use A\B does the same job and detects structure automatically.
Input arguments
A- Coefficient matrix.
B- Right-hand side, a vector or a matrix with
size(A,1)rows. opts- Struct of logical fields describing
A.TRANSA = truesolves withA'.
Output arguments
X- The solution.
Example
General, upper triangular and transposed solves
A = [2 1; 1 3];
b = [3; 5];
x = linsolve(A, b)
opts.UT = true;
linsolve([2 1; 0 3], b, opts)
opts2.TRANSA = true;
linsolve([2 0; 1 3], b, opts2)
Output
x = 2×1
0.8000
1.4000
ans = 2×1
0.6667
1.6667
ans = 2×1
0.6667
1.6667