PH15720 MathCAD worksheet 5 – Data Handling The aim of this worksheet is to introduce you to the use of vectors and matrices to handle experimental data in MathCAD. By the end of this worksheet you should be able to: Use a matrix to hold experimental data. Extract columns of readings from the data Plot experimental data on a graph Fit a straight line to the data. Compare theoretical and experimental results. One of the commonest analysis techniques in experimental physics is to take a series of measurements of some quantity and then to plot those readings. Some parameters are extracted by analysing the data and a theoretical model of the experiment constructed. The theoretical model is then compared with the experimental data to assess its validity. In this worksheet we will perform these tasks on a very simple experiment, in this case an experiment to determine the value of a resistor. Various voltages are applied across the resistor and the resultant current measured. We will use mathCAD to plot the Current against Voltage for the resistor and then take a best line plot through the data and use this to calculate the value of the unknown resistor. The Applied voltage and measured current and shown below: (Note that these values are different from those in the lecture slide) Vapplied Imeasured (Volts) (ma) 0 0 0.5 0.465 1 0.923 1.5 1.387 2 1.869 2.5 2.337 3 2.811 3.5 3.287 4 3.747 4.5 4.177 © DPL 2002,3,5,6 1 PH15720 MathCAD Worksheet 5 We will start by creating a matrix to hold all of these values and then separate it into two vectors, one to hold the applied voltages, the other to hold the measured currents. Create an input table to hold the values taken from the experiment. Select Insert|Data|Table from the menu. MathCAD will create a blank input table with 2 rows and 2 columns visible initially. In the selection rectangle to the left of the := sign, give the input table a name, such as ‘Readings’. Select the Input table and move the cursor around the edge until the cursor becomes a re-sizing arrow. Draw the re-sizing arrow until the input table has 10 rows and 2 columns visible. Right click the table and select properties from the pop-up menu. Change the displayed precision to 3 digits. Fill in the experimental data from the table above. Don’t worry about units or the fact that the current is in milliAmps rather than Amps for now. Your worksheet should look a bit like that show below: Readings 0 0 1 2 3 4 5 6 7 8 9 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 1 0 0.465 0.923 1.387 1.869 2.337 2.811 3.287 3.747 4.177 We will now separate the readings into two vectors, one to hold the applied voltages and the other to hold the measured currents. At the same time we will multiply the bare numbers by appropriate units. It may seem a bit long winded to put all the data into one matrix before separating it out into its component parts, but having all the readings in one place helps to ensure that we get all the readings lined up. If we entered the data directly into two separate vectors it would be easy to miss out a reading from one of the vectors, so the two sets would not line up. © DPL 2002,3,5,6 2 PH15720 MathCAD Worksheet 5 MathCAD has an operator to extract a single column from a matrix. The operator is written like this: M<> and can be found on the matrix toolbar. The keyboard shortcut <ctrl-6> will also insert the operator. The number of the column you wish to extract is put in the placeholder between the angle brackets. Columns are normally numbered from 0 Below the input table type a name for the vector to hold the applied voltages. Press : to create an assignment operator. Type the name of the matrix you wish to extract columns from, in this case ‘Readings’ Select the column extract operator from the matrix toolbar. Put the column number for the voltage readings in the placeholder between the angle brackets. Multiply the whole expression by appropriate units (V) to get correct units into the vector. Repeat the process for the measured currents, multiplying them by mA to get the correct units. Once you have created the two vectors, print them out to check that everything has worked ok so far. This portion of the worksheet should look like: 0 Readings V 1 IMeas ured Readings mA VApplied 0 1 2 3 VApplied 4 5 6 7 8 9 © DPL 2002,3,5,6 0 0 0.5 1 1.5 2 V 2.5 3 3.5 4 4.5 0 0 1 2 3 IMeas ured 4 5 6 7 8 9 0 4.65·10 -4 9.23·10 -4 1.387·10 -3 1.869·10 -3 A 2.337·10 -3 2.811·10 -3 3.287·10 -3 3.747·10 -3 4.177·10 -3 3 PH15720 MathCAD Worksheet 5 Now the data is in the worksheet, we can start to plot and analyse it. We will start by plotting the data on an X-Y graph. Insert an X-Y plot and drag it to a reasonable size. In the X-Axis placeholder type the name of the vector holding the applied voltages. In the Y-Axis placeholder, type the name of the vector holding the measured currents. Since the graph is of a set of discrete readings, rather than a continuous curve, format the trace to plot points show by circles. The graph should look like the one shown below: 3 4.177 10 0.005 0.004 0.003 IMeasured 0.002 0.001 0 0 0 1 0 2 3 VApplied 4 5 4.5 We will now use this data to calculate the slope of the graph and from this the unknown resistance. We will then use the value of the observed resistance to plot the predicted current and check this is close to the measured. Use the slope function to calculate the slope of the best straight line fit through the points. This slope is the slope of IMeasured vs VApplied, so the resistance is given by its reciprocal. RUnknown 1 s lope( VApplied IMeas ured) RUnknown 1.07 10 3 © DPL 2002,3,5,6 4 PH15720 MathCAD Worksheet 5 In this case it is very easy to forget to take the reciprocal when calculating the slope. Notice how the way that using units with mathCAD can avoid this mistake. In order to check the result, we will create a function which will give the theoretical current through our unknown resistor for any applied voltage. From ohms law, we know that the current through a resistor is given by the applied voltage divided by the resistance of the resistor, thus we can easily construct a model of the resistor as a function in mathCAD. Create a function, ITheory(vv), which gives the theoretical current for an applied voltage vv. Having created the function, test it at a couple of applied voltages and compare the results with the experimental data. ITheory( vv) vv RUnknown ITheory( 1 V) 0.935 mA ITheory( 2 V) 1.87 10 3 A MathCAD will allow us to mix vectors and functions on the same graph. We will use mathCAD’s quickplot facility with the graph from earlier to plot the theorectical and experimental data on the same graph. Copy and past the graph from above into the worksheet below the definition of ITheory Put a comma after the VApplied item on the x-axis Type ‘va’ as the name of a temporary variable which mathCAD will fill with values to do the plot. Type a comma after the IMeasured term on the Y-axis. Type ITheory(va) in the placeholder which appeared after the comma. Click out of the graph to see the results. You should format the graph traces to show the theoretical result as a solid line. Change the x-axis range to go from 0 to 5 volts Your graph should look like the one below: © DPL 2002,3,5,6 5 PH15720 MathCAD Worksheet 5 0.005 0.004 0.003 IMeasured ITheory ( va ) 0.002 0.001 0 0 1 2 3 4 5 VApplied va When there are 0 volts applied across a resistor, there should be no current flowing through it. Check this using the intercept() function on the data sets. © DPL 2002,3,5,6 6