linsolve

Solve a linear system of equations.

Syntax

x = linsolve(A,b)

x = linsolve(A,b,opt)

Inputs

A
The left-hand side matrix.
Dimension: matrix
b
The right-hand side vector or matrix.
Dimension: vector | matrix
opt
Options argument. See Comments.
Dimension: struct

Outputs

x
The solution vector or matrix.

Example

Positive definite example.

a=[3,1;1,3];
b=[1;2];
opt = struct('POSDEF', {true});
x=linsolve(a,b,opt)
x = [Matrix] 2 x 1
0.12500
0.62500

Rectangular example.

a=[1,2;3,4;5,8];
b=[1;2;3];
opt = struct('RECT', {true});
x=linsolve(a,b,opt)
x = [Matrix] 2 x 1
0.50000
0.08333

Comments

The solution to the system is the same as x = A\b when no option is specified. If the structure opt is provided, linsolve passes the information about A to specify which algorithm to use. Current options for opt are:
  • POSDEF: positive definite
  • RECT: general rectangular