Simultaneous Equations
- Linear
Algebra -
Solving a
system of simultaneous equations is easy in Matlab. It is, maybe, the most used
operation in science and engineering, too. Solving a set of equations in linear algebra on a computer is nowadays as basic as doing arithmetic additions using
a calculator. Let's see how easy Matlab makes this task.
We'll solve the set of
linear equations
given below. To solve these equations, no prior knowledge of matrix
algebra or linear methods is required. The first two steps described
below are really
basic for most people who know a just little bit of linear algebra.
Consider
the following set of equations for our example.
-6x = 2y - 2z + 15
4y - 3z = 3x + 13
2x + 4y - 7z = -9
First,
rearrange the equations.
Write each equation with all unknown
quantities on the left-hand side and all known quantities on the right
side. Thus, for the equations given, rearrange them such that all terms
involving x,
y
and z are
on the left side of the equal sign.
-6x - 2y + 2z = 15
-3x + 4y - 3z = 13
2x
+ 4y - 7z = -9
Second, write
the equations in a matrix form.
To write the equations in the matrix form Ax
= b,
where x
is the vector of unknowns, you have to arrange the unknowns in vector x,
the coefficients of the unknowns in matrix A
and the constants on the rigth hand of the equations in vector b.
In this particualar example, the unknown column vector is
x
= [x y z]'
the coefficient matrix is
A
= [-6 -2 2
-3 4 -3
2 4 -7]
and the known constant column vector is
b
= [15 13 -9]'
Note than the columns of A
are simply the coefficients of each unknown from all the three
expressed equations. The apostrophe
at the end of vectors x
and b
means that those vectors are column vectors, not row ones (it is Matlab
notation).
Third, solve
the simultaneous equations in Matlab.
Enter the matrix A
and vector b,
and solve for vector x
with the instruction 'x = A\b' (note that the '\' sign is different
from the ordinary
division '/'
sign).
The Matlab answer is:
A =
-6
-2 2
-3
4 -3
2
4 -7
b =
15
13
-9
x =
-2.7273
2.7727
2.0909
>>
You can test the result by performing the substitution and multiplying Ax
to get b,
like this:
A*x
And the Matlab answer is:
ans =
15.0000
13.0000
-9.0000
>>
which corresponds to b,
indeed.
Was it easy
enough?
From
'Simultaneous Equations' to home
From
'Simultaneous Equations' to 'Linear Algebra Menu'
Table of Contents


|