Solves the general linear system Ax = b. For over determined systems (A has more rows than columns), the system is solved in the least squares sense. LSolve uses LU decomposition for a square matrix; QR otherwise. |
||
Syntax |
x = LSolve(A,b) |
|
Arguments |
Name |
Description |
A |
A matrix of real values. Number of rows must be equal or greater than number of columns. |
|
b |
The right-hand side column vector or a matrix. If it is a matrix, each column is considered a separate vector and the system is solved separately for each, resulting in multiple solutions. The number of rows must be equal to the number of rows of matrix A. |
|
Output |
Name |
Description |
x |
The solution(s) to the system(s). It will have the same dimension as the right-hand side argument b. Each column will be a solution corresponding to the equivalent column in b. |
|
Example 1 |
Solve a pair of linear systems Ax=b for the same matrix A. |
|
Syntax |
||
A = [1,2,3;41,15,6;17,8,9];// square matrix A b = [11,21;13,33;21,24]; // Two columns(i.e. 2 rhs) x = LSolve(A,b); // Solve for each right hand side |
||
ResultEach column is a solution for the corresponding right hand side. |
||
x = -1.5 -5.4079 4.5 18.355 1.1667 -3.4342 |
||
Example 2 |
Find the best fit solution to the system y = 0 3x - y = 0 3x + y = 6 |
|
Syntax |
||
A = [0, 1; 3, -1; 3, 1] b = [0; 0; 6] x = LSolve(A, b) |
||
ResultA least squares solution to the system. x = 1 2 |
||
See Also: |