Difference between revisions of "Linear Systems in Matlab"
m (→Solving Linear Systems of Equations in MATLAB) |
|||
Line 3: | Line 3: | ||
== Solving Linear Systems of Equations in MATLAB == | == Solving Linear Systems of Equations in MATLAB == | ||
− | <math>[A](x)=(b)</math> | + | This section discusses how to solve a set of linear equations <math>[A](x)=(b)</math> in MATLAB. |
− | See the discussion of [[LinearAlgebra|linear algebra]] for help on | + | See the discussion of [[LinearAlgebra|linear algebra]] for help on writing a linear system of equations in matrix-vector format. There is also help on [[Matlab_Arrays#Creating Arrays in Matlab|creating matrices and vectors]] in MATLAB. |
The simplest way of solving a system of equations in MATLAB is by using the '''\''' operator. Given a matrix '''A''' and a vector '''b''', we may solve the system using the following MATLAB commands | The simplest way of solving a system of equations in MATLAB is by using the '''\''' operator. Given a matrix '''A''' and a vector '''b''', we may solve the system using the following MATLAB commands |
Revision as of 14:10, 18 August 2008
Solving Linear Systems of Equations in MATLAB
This section discusses how to solve a set of linear equations in MATLAB.
See the discussion of linear algebra for help on writing a linear system of equations in matrix-vector format. There is also help on creating matrices and vectors in MATLAB.
The simplest way of solving a system of equations in MATLAB is by using the \ operator. Given a matrix A and a vector b, we may solve the system using the following MATLAB commands
x = A\b;
For example, if we wanted to solve the system of equations
we would first rewrite these in a matrix-vector form as
This is implemented in MATLAB as
A = [ 5 6; 3 1 ]; % define the matrix
b = [ 0; -5 ]; % define the vector
solution = A\b; % solve the system of equations.
In this example, solution is a column vector whose elements are x and y.
Note that we can also form the inverse of a matrix,
This can be done in MATLAB as illustrated by the following:
A = [ 5 6; 3 1 ];
b = [ 0; -5 ];
Ainv = A^-1; % calculate the inverse of A
solution = Ainv*b; % calculate the solution
We could also calculate A-1 by
Ainv = inv(A); % entirely equivalent to A^-1.
Sparse Systems
|
Linear Systems using the Symbolic Toolbox
Occasionally we may want to find the symbolic (general) solution to a system of equations rather than a specific numerical solution. The symbolic toolbox provides a way to do this.
|