您在這裡

Example 2.11

8 十月, 2015 - 17:29

Let’s solve the following simultaneous equations:

\begin{align*} x+y &= 1\\ 2x-5y&=9 \end{align*}

First, we will create a matrix for the left-hand side of the equation using the coefficients, namely 1 and 1 for the first and 2 and -5 for the second. The matrix looks like this:
\bigl(\begin{smallmatrix} 1 & 1\\ 2 & -5 \end{smallmatrix}\bigr)

The above matrix can be entered in the command window by typing A=[1 1; 2 -5].

Second, we create a column vector to represent the right-hand side of the equation as follows: \binom{1}{9}

The above column vector can be entered in the command window by typing B= [1;9].

To solve the simultaneous equation, we will use the left division operator and issue the following command: C=A\B. These three steps are illustrated below:

    » A=[1 1; 2 -5]
A =

     1  1
     2 -5
» B= [1;9]
B =

     1
     9

» C=AnB

C =

     2
    -1

»

The result C indicating 2 and 1 are the values for x and y, respectively.