This has the general form
A I = b
where, in general, A is an n by n matrix (n rows, n columns), b is an n by 1 column
vector, and I is an n by 1 unknown vector to solve for. In this example, you will enter
the following sequence:
A = [30 -10; -10 25]
b = [150 -100]
I = A \ b
The \ operator invokes the Gaussian elimination algorithm and the
(transpose symbol) transforms b from a row vector to a column vector. Adding a ;
(semicolon) to the end of each statement will stop MATLAB from displaying the matrix you
have just entered. For this lab, it is recommended you do not end your statements with a
semicolon.
2. You will now solve the system of equations given in equations (1) and (2)
using MATLAB. Follow the instructions listed here.
a. From windows, to call up MATLAB, go down to the taskbar and click on the Start
button. Go to the Programs menu and bring up the MATLAB for Windows
menu. Select the MATLAB icon. A MATLAB working window will appear. At the prompt, type
"diary". (More about "diary" later).
b. Type the following commands in the MATLAB window. A brief explanation of each
command appears after it. Notice that after you enter each vector, it will be echoed back
on your screen.
A
= [30 -10; -10 25]
establishes
the 2 x 2 "A" matrix
b
= [150 -100]
establishes
"b" as a 2 x 1 column vector
(the
mark changes b from a row vector to a column vector)
I
= A \ b
Invoke
the Gaussian elimination algorithm
c. The "I" matrix that appears after you entered the Gaussian
operator is the solution matrix for I1 and I2. You should see a
matrix that looks like this, where the value for I1 is equal to 4.2308 and I2
is equal to -2.3077. If you did not get these values, review each of the commands you
entered by pressing the up arrow. Make corrections to any mistakes you find and run the
last command again.
3. Solve each of the following systems of linear equations using MATLAB. Verify
your results by
substituting the solutions back into the original equations.
a. x1 + 4x2 + 5x3 = -1
b. x1 - 4x2 + 2x3 + x4 = 8
c. x1
+ (1+j)x2 + (3-2j)x3 = 7 - j
3x1 - 2x2 + 6x3 =
13 -4x1
+ 3x3 - x4 = -1
(1- j)x1 + 2x2 + (-2+2j)x3 = -7+3j
4x1 - 2x3 = 2
2x1 + 3x2 + 5x4 = 17
(3+2j)x1 + (-2-2j)x2 + 4x3
= 12-j
x1 - x2 + 5x3 - 5x4 = -4
Note: Complex numbers may be expressed using i or j in MATLAB. Since earlier in the
session you used
an I (for current), we choose to express problem (c) above with js. Using
is in problem (c) would have resulted in confusion with the earlier matrix. You will
also need to use the . operator when entering the complex number matrix (problem
(c)), otherwise the conjugate of the column vector will be used to solve the system. YOU
WILL NOT OBTAIN THE CORRECT ANSWER IF YOU DO NOT USE THE .OPERATOR!
4. Exit MATLAB. Look in your directory and find diary. Browse diary
either from a MS-DOS window using the type command or from any of the
editors present on the windows desktop. Print out a copy of the diary and paste it in your
lab book.
Questions:
1. From your observations in part I of this lab, is Ohms Law obeyed for
the resistor?
2. In part I of the lab, describe the impact of the voltmeter and ammeter
resistances on the accuracy of your circuit. If you were to move the voltmeter from the
resistor to a position across the source, would this significantly change your voltage
readings? Why or why not?
3. What is the command "diary" for in MATLAB?