EE 101

Lab Exercise 4: Ohm’s Law and Simultaneous Equation Solution Using MATLAB

(There is no pre-lab exercise for this lab)

Part I - Ohm’s Law. V vs. I for a Resistor.

1. Using a 22 Kohm resistor, verify that Ohm’s Law is obeyed by measuring I and V for several voltages.

Build the circuit below. Take care to properly connect a voltage meter across your load resistor and a current meter in series with the resistor. You will need to use both positive and negative values for Vs, so for half of these values your circuit should be powered by the adjustable 5 to 15 Vdc source, and for the rest it should be hooked to the -5 to -15 Vdc source. Note that the protoboard’s adjustable voltage sources may range below 5 Vdc and/or above 15 Vdc.

a. Construct a function table in your lab book showing the current through the 22 Kohm resistor versus the voltage across the resistor. Use at least 5 positive and 5 negative voltage values.

b. Construct a graph of V vs. I in your lab book. Fully label your graph, and use a straight-edge to draw your axes and to extrapolate a line from your data. Use the vertical axis for V and the horizontal for I.

c. From the plot, determine the value of the resistor. Do this by deriving an equation, V = IR, where the value of R is determined from the slope of your line. As always, be sure to show your work!

Part II - Solving Simultaneous Equations Using MATLAB (Gaussian elimination method).

The purpose of this part of the lab is to learn how to solve a system of linear simultaneous equations using MATLAB. In class we solved the following system by using the Gaussian elimination method.

30 I1 - 10 I2 = 150 (1)

-10 I1 + 25I2 = -100 (2)

In MATLAB, this is done with the use of the \ (backslash) operator or matrix left division. In order to do that, MATLAB requires us to input the coefficients of the system in a two dimensional array, also known as a matrix. Equations (1) and (2) can be written in matrix form as follows:

 

=

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 j’s. Using i’s 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 Ohm’s 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?