Let’s solve the following simultaneous equations:
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:
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:
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.
- 瀏覽次數:1275