<html><head><title></title><style type="text/css"> p { margin: 0 0 0 0; font-family: Arial, sans-serif; font-size:10pt; font-weight: normal; font-style: normal; vertical-align: baseline; color: black; text-decoration: none; } div { border-width:0px; border-style: solid; border-color: red; } body { background-color: #fff; } p img { vertical-align: middle; } p b, li b { font-weight : bold; } p i, li i { font-style : italic; } p u, li u { text-decoration : underline; } p so, li so { text-decoration : line-through; } p sub, p sub { font-size : 70%; vertical-align: sub; } p sup, p sup { font-size : 70%; vertical-align: super; } ul { padding-left : 2em; /* for mozilla list marker box */ margin-left : 0; /* for IE list marker box */ } ol { padding-left : 2em; /* for mozilla list marker box */ margin-right : -0.5em; margin-left : 0; /* for IE list marker box */ } p.Style1, li.Style1 /*Normal*/ { margin-left: 0pt; margin-right: 0pt; text-align: left; font-family: 'Arial', sans-serif;; font-size: 10pt;font-weight: normal; font-style: normal; vertical-align: baseline; } p.Style2, li.Style2 /*Heading 1*/ { margin-left: 0pt; margin-right: 0pt; text-align: left; font-family: 'Arial', sans-serif;; font-size: 13.26315789473684pt;font-weight: bold; font-style: normal; vertical-align: baseline; } p.Style3, li.Style3 /*Heading 2*/ { margin-left: 0pt; margin-right: 0pt; text-align: left; font-family: 'Arial', sans-serif;; font-size: 12pt;font-weight: bold; font-style: italic; vertical-align: baseline; } p.Style4, li.Style4 /*Heading 3*/ { margin-left: 0pt; margin-right: 0pt; text-align: left; font-family: 'Arial', sans-serif;; font-size: 12pt;font-weight: normal; font-style: normal; vertical-align: baseline; } p.Style5, li.Style5 /*Paragraph*/ { margin-left: 0pt; margin-right: 0pt; text-indent: 21pt; text-align: left; font-family: 'Arial', sans-serif;; font-size: 10pt;font-weight: normal; font-style: normal; vertical-align: baseline; } p.Style6, li.Style6 /*List*/ { margin-left: 14.4pt; margin-right: 0pt; text-indent: -14.4pt; text-align: left; font-family: 'Arial', sans-serif;; font-size: 10pt;font-weight: normal; font-style: normal; vertical-align: baseline; } p.Style7, li.Style7 /*Indent*/ { margin-left: 108pt; margin-right: 0pt; text-align: left; font-family: 'Arial', sans-serif;; font-size: 10pt;font-weight: normal; font-style: normal; vertical-align: baseline; } p.Style8, li.Style8 /*Title*/ { margin-left: 0pt; margin-right: 0pt; text-align: center; font-family: 'Times New Roman', sans-serif;; font-size: 24pt;font-weight: bold; font-style: normal; vertical-align: baseline; } p.Style9, li.Style9 /*Subtitle*/ { margin-left: 0pt; margin-right: 0pt; text-align: center; font-family: 'Times New Roman', sans-serif;; font-size: 18pt;font-weight: normal; font-style: normal; vertical-align: baseline; } </style></head><body><div id="mc-region-2" style="position: absolute; top: 11.4pt; left: 6pt; width: 410.6pt; "><a name="" /><p class="Style1"><span style="font-size: 13.26315789473684pt; ">Regression with MathCAD</span></p><p class="Style1"></p><p class="Style1">MathCAD provides built-in functions to calculate slope and intercepts for datasets.</p><p class="Style1"></p><p class="Style1">The built-in functions (line, slope, intercept) provide linear regression ananlysis assuming that the error on the y measurements is the same for each data point in the dataset.</p><p class="Style1">In this exercise we will demonstrate how the built-in functions work and then go on to program our own regression functions; firstly as copies of the buil-ins and then to account for different errors on the data.</p></div><div id="mc-region-9" style="position: absolute; top: 159pt; left: 12pt; width: 156.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0003_17808587.PNG" id="generatedImage9" path=".\regression_images/IMG0003_17808587.PNG" style="width: 156.6pt;height: 148.8pt;"></img></div><div id="mc-region-10" style="position: absolute; top: 201pt; left: 192pt; width: 180.8pt; "><a name="" /><p class="Style1">use a data table to store our initial data set</p></div><div id="mc-region-14" style="position: absolute; top: 316.8pt; left: 6pt; width: 74.4pt; "><a name="" /><img border="0" src=".\regression_images/IMG0004_17808597.PNG" id="generatedImage14" path=".\regression_images/IMG0004_17808597.PNG" style="width: 74.4pt;height: 16.8pt;"></img></div><div id="mc-region-185" style="position: absolute; top: 327pt; left: 186pt; width: 225.2pt; "><a name="" /><p class="Style1">Use column extract operators to get individual column data</p></div><div id="mc-region-15" style="position: absolute; top: 334.8pt; left: 6pt; width: 74.4pt; "><a name="" /><img border="0" src=".\regression_images/IMG0005_17808607.PNG" id="generatedImage15" path=".\regression_images/IMG0005_17808607.PNG" style="width: 74.4pt;height: 16.8pt;"></img></div><div id="mc-region-19" style="position: absolute; top: 369pt; left: 6pt; width: 164.6pt; "><a name="" /><p class="Style1">Now we can take a first plot of the data</p></div><div id="mc-region-20" style="position: absolute; top: 390pt; left: 6pt; width: 232.2pt; "><a name="" /><img border="0" src=".\regression_images/IMG0007_17808607.PNG" id="generatedImage20" path=".\regression_images/IMG0007_17808607.PNG" style="width: 232.2pt;height: 181.2pt;"></img></div><div id="mc-region-24" style="position: absolute; top: 405pt; left: 264pt; width: 150.2pt; "><a name="" /><p class="Style1">Use plot format to show points as o symbols</p></div><div id="mc-region-31" style="position: absolute; top: 600pt; left: 6pt; width: 398pt; "><a name="" /><p class="Style1">The error in y data is given as <span style="font-size: 12pt; font-family: 'Symbol', sans-serif;">s</span>y = 0.2</p><p class="Style1"></p><p class="Style1">We can use vector arithmatic to create vectors showing the high and low points of the error bars</p></div><div id="mc-region-35" style="position: absolute; top: 650.4pt; left: 6pt; width: 42pt; "><a name="" /><img border="0" src=".\regression_images/IMG0008_17808627.PNG" id="generatedImage35" path=".\regression_images/IMG0008_17808627.PNG" style="width: 42pt;height: 13.2pt;"></img></div><div id="mc-region-36" style="position: absolute; top: 674.4pt; left: 6pt; width: 96pt; "><a name="" /><img border="0" src=".\regression_images/IMG0009_17808637.PNG" id="generatedImage36" path=".\regression_images/IMG0009_17808637.PNG" style="width: 96pt;height: 13.2pt;"></img></div><div id="mc-region-37" style="position: absolute; top: 692.4pt; left: 6pt; width: 97.2pt; "><a name="" /><img border="0" src=".\regression_images/IMG0010_17808647.PNG" id="generatedImage37" path=".\regression_images/IMG0010_17808647.PNG" style="width: 97.2pt;height: 13.2pt;"></img></div><div id="mc-region-38" style="position: absolute; top: 744pt; left: 6pt; width: 245.4pt; "><a name="" /><img border="0" src=".\regression_images/IMG0012_17808647.PNG" id="generatedImage38" path=".\regression_images/IMG0012_17808647.PNG" style="width: 245.4pt;height: 181.2pt;"></img></div><div id="mc-region-40" style="position: absolute; top: 759pt; left: 270pt; width: 146pt; "><a name="" /><p class="Style1">Format the traces for yLoErr1 and yHiErr1 to be both of type 'error' to get the graph as shown here</p></div><div id="mc-region-44" style="position: absolute; top: 939pt; left: 6pt; width: 403.4pt; "><a name="" /><p class="Style1">The slope and intercept functions will determine the parameters of our least square fit to the data.</p></div><div id="mc-region-45" style="position: absolute; top: 963pt; left: 6pt; width: 111pt; "><a name="" /><img border="0" src=".\regression_images/IMG0013_17808657.PNG" id="generatedImage45" path=".\regression_images/IMG0013_17808657.PNG" style="width: 111pt;height: 12.6pt;"></img></div><div id="mc-region-74" style="position: absolute; top: 963pt; left: 216pt; width: 51.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0014_17808667.PNG" id="generatedImage74" path=".\regression_images/IMG0014_17808667.PNG" style="width: 51.6pt;height: 12.6pt;"></img></div><div id="mc-region-46" style="position: absolute; top: 987pt; left: 6pt; width: 120.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0015_17808677.PNG" id="generatedImage46" path=".\regression_images/IMG0015_17808677.PNG" style="width: 120.6pt;height: 12.6pt;"></img></div><div id="mc-region-76" style="position: absolute; top: 987pt; left: 216pt; width: 49.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0016_17808687.PNG" id="generatedImage76" path=".\regression_images/IMG0016_17808687.PNG" style="width: 49.8pt;height: 12.6pt;"></img></div><div id="mc-region-48" style="position: absolute; top: 1011pt; left: 6pt; width: 227pt; "><a name="" /><p class="Style1">Now we can create a function to model our best line fit</p></div><div id="mc-region-49" style="position: absolute; top: 1035pt; left: 6pt; width: 79.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0017_17808687.PNG" id="generatedImage49" path=".\regression_images/IMG0017_17808687.PNG" style="width: 79.8pt;height: 12.6pt;"></img></div><div id="mc-region-51" style="position: absolute; top: 1068pt; left: 12pt; width: 241.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0019_17808697.PNG" id="generatedImage51" path=".\regression_images/IMG0019_17808697.PNG" style="width: 241.8pt;height: 181.2pt;"></img></div><div id="mc-region-61" style="position: absolute; top: 1083pt; left: 270pt; width: 145.4pt; "><a name="" /><p class="Style1">Note that we have to include the xdata1 vector 3 times on the list of x arguments to match up with the corresponding y-axis arguments</p></div><div id="mc-region-64" style="position: absolute; top: 1263pt; left: 6pt; width: 410pt; "><a name="" /><p class="Style1">In order to tidy up the graph, go to the traces page of the format dialog and hide the arguments and show the legend. You should also change the names of the traces to indicate their purpose. </p></div><div id="mc-region-66" style="position: absolute; top: 1290pt; left: 12pt; width: 251.4pt; "><a name="" /><img border="0" src=".\regression_images/IMG0021_17808707.PNG" id="generatedImage66" path=".\regression_images/IMG0021_17808707.PNG" style="width: 251.4pt;height: 247.2pt;"></img></div><div id="mc-region-72" style="position: absolute; top: 1557pt; left: 6pt; width: 398pt; "><a name="" /><p class="Style1">The line() function does the same job as the slope() and intercept() functions but returns both the slope and intercept at the same time, as two elements of a vector.</p></div><div id="mc-region-73" style="position: absolute; top: 1596.6pt; left: 6pt; width: 131.4pt; "><a name="" /><img border="0" src=".\regression_images/IMG0022_17808727.PNG" id="generatedImage73" path=".\regression_images/IMG0022_17808727.PNG" style="width: 131.4pt;height: 29.4pt;"></img></div><div id="mc-region-78" style="position: absolute; top: 1635pt; left: 6pt; width: 267.8pt; "><a name="" /><p class="Style1">You can assign both variables at once using the following syntax</p></div><div id="mc-region-79" style="position: absolute; top: 1656.6pt; left: 6pt; width: 117pt; "><a name="" /><img border="0" src=".\regression_images/IMG0023_17808737.PNG" id="generatedImage79" path=".\regression_images/IMG0023_17808737.PNG" style="width: 117pt;height: 29.4pt;"></img></div><div id="mc-region-80" style="position: absolute; top: 1701pt; left: 12pt; width: 49.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0024_17808737.PNG" id="generatedImage80" path=".\regression_images/IMG0024_17808737.PNG" style="width: 49.8pt;height: 12.6pt;"></img></div><div id="mc-region-81" style="position: absolute; top: 1719pt; left: 12pt; width: 51.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0025_17808747.PNG" id="generatedImage81" path=".\regression_images/IMG0025_17808747.PNG" style="width: 51.6pt;height: 12.6pt;"></img></div><div id="mc-region-84" style="position: absolute; top: 1763.4pt; left: 6pt; width: 410pt; "><a name="" /><p class="Style1"><span style="font-size: 13.26315789473684pt; ">Create our own regression functions</span></p><p class="Style1"></p><p class="Style1">Using the programming facilities of mathCAD we will create our own regression functions, firstly as a copy of the built-in, line() function and then as a function to calculate a weighted regression.</p></div><div id="mc-region-89" style="position: absolute; top: 1821pt; left: 6pt; width: 381.8pt; "><a name="" /><p class="Style1" style="margin-left: 0pt; margin-right: 0pt; text-align: left;">Our regression function looks like the program below. Note that, the for loop comes from the programming toolbar and that the sigma character comes from the greek toolbar. </p></div><div id="mc-region-90" style="position: absolute; top: 1857pt; left: 6pt; width: 327pt; "><a name="" /><img border="0" src=".\regression_images/IMG0026_17808757.PNG" id="generatedImage90" path=".\regression_images/IMG0026_17808757.PNG" style="width: 327pt;height: 358.8pt;"></img></div><div id="mc-region-97" style="position: absolute; top: 2229pt; left: 12pt; width: 345.8pt; "><a name="" /><p class="Style1">We can use our test data to prove that the output is the same as the built-in function</p></div><div id="mc-region-94" style="position: absolute; top: 2250.6pt; left: 6pt; width: 145.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0027_17808767.PNG" id="generatedImage94" path=".\regression_images/IMG0027_17808767.PNG" style="width: 145.8pt;height: 29.4pt;"></img></div><div id="mc-region-99" style="position: absolute; top: 2295pt; left: 6pt; width: 410pt; "><a name="" /><p class="Style1">The trace() function in the code is useful for checking values in our program. </p><p class="Style1"></p><p class="Style1">In order to see it working, make sure that the debugging toolbar is visible (View|Toolbars|Debugging) and make sure the 'Toggle debugging' button is pressed in. The results of the program trace will apear in the trace window at the bottom of the mathCAD screen.</p><p class="Style1"></p><p class="Style1">the trace function takes a variable number of arguments, the first being a string which gives a picture of what the output is to look like. The second and follwoing areguments are substituted into the string, replacing the {0} {1} {2} bits.</p></div><div id="mc-region-103" style="position: absolute; top: 2411.4pt; left: 6pt; width: 405.8pt; "><a name="" /><p class="Style1"><span style="font-size: 13.26315789473684pt; ">Regression with weighted mean</span></p><p class="Style1"></p><p class="Style1">The regression program with a weighted mean calculates a weighting factor depending on the error in the y data for each point. Thus our program takes 3 parameters, X, Y and <span style="font-size: 12pt; font-family: 'Symbol', sans-serif;"><span style="font-weight: normal; font-style: normal;">s</span></span><span style="font-size: 10pt; font-family: 'Arial', sans-serif;"><span style="font-weight: normal; font-style: normal;">Y each being a vector of values. Copy and paste the program from above before modifying it</span></span></p></div><div id="mc-region-104" style="position: absolute; top: 2486.4pt; left: 6pt; width: 373.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0028_17808787.PNG" id="generatedImage104" path=".\regression_images/IMG0028_17808787.PNG" style="width: 373.8pt;height: 429.6pt;"></img></div><div id="mc-region-106" style="position: absolute; top: 2937pt; left: 6pt; width: 272pt; "><a name="" /><p class="Style1">We can use this in the 'cup of tea' experiment from the worksheet</p></div><div id="mc-region-109" style="position: absolute; top: 2967pt; left: 6pt; width: 55.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0029_17808797.PNG" id="generatedImage109" path=".\regression_images/IMG0029_17808797.PNG" style="width: 55.8pt;height: 96.6pt;"></img></div><div id="mc-region-112" style="position: absolute; top: 2967pt; left: 126pt; width: 84pt; "><a name="" /><img border="0" src=".\regression_images/IMG0030_17808807.PNG" id="generatedImage112" path=".\regression_images/IMG0030_17808807.PNG" style="width: 84pt;height: 96.6pt;"></img></div><div id="mc-region-119" style="position: absolute; top: 3117pt; left: 12pt; width: 34.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0031_17808817.PNG" id="generatedImage119" path=".\regression_images/IMG0031_17808817.PNG" style="width: 34.8pt;height: 12.6pt;"></img></div><div id="mc-region-124" style="position: absolute; top: 3140.4pt; left: 6pt; width: 93pt; "><a name="" /><img border="0" src=".\regression_images/IMG0032_17808827.PNG" id="generatedImage124" path=".\regression_images/IMG0032_17808827.PNG" style="width: 93pt;height: 13.2pt;"></img></div><div id="mc-region-126" style="position: absolute; top: 3141pt; left: 162pt; width: 140.6pt; "><a name="" /><p class="Style1">Calculate temperature difference</p></div><div id="mc-region-128" style="position: absolute; top: 3165pt; left: 6pt; width: 52.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0033_17808827.PNG" id="generatedImage128" path=".\regression_images/IMG0033_17808827.PNG" style="width: 52.8pt;height: 96.6pt;"></img></div><div id="mc-region-130" style="position: absolute; top: 3207pt; left: 108pt; width: 181.4pt; "><a name="" /><p class="Style1">displayed in Kelvin</p><p class="Style1"></p><p class="Style1">To display in deg c, select placeholder and</p><p class="Style1">put Temperature difference unit in place</p></div><div id="mc-region-133" style="position: absolute; top: 3171pt; left: 306pt; width: 52.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0034_17808837.PNG" id="generatedImage133" path=".\regression_images/IMG0034_17808837.PNG" style="width: 52.8pt;height: 96.6pt;"></img></div><div id="mc-region-138" style="position: absolute; top: 3303pt; left: 6pt; width: 114.8pt; "><a name="" /><p class="Style1">Plot temperature over time</p></div><div id="mc-region-139" style="position: absolute; top: 3336pt; left: 6pt; width: 272.4pt; "><a name="" /><img border="0" src=".\regression_images/IMG0036_17808847.PNG" id="generatedImage139" path=".\regression_images/IMG0036_17808847.PNG" style="width: 272.4pt;height: 217.2pt;"></img></div><div id="mc-region-143" style="position: absolute; top: 3620.4pt; left: 12pt; width: 58.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0037_17808857.PNG" id="generatedImage143" path=".\regression_images/IMG0037_17808857.PNG" style="width: 58.8pt;height: 13.2pt;"></img></div><div id="mc-region-145" style="position: absolute; top: 3621pt; left: 138pt; width: 195.8pt; "><a name="" /><p class="Style1">Calculate natural log of temperature difference</p></div><div id="mc-region-146" style="position: absolute; top: 3650.4pt; left: 12pt; width: 31.2pt; "><a name="" /><img border="0" src=".\regression_images/IMG0038_17808867.PNG" id="generatedImage146" path=".\regression_images/IMG0038_17808867.PNG" style="width: 31.2pt;height: 13.2pt;"></img></div><div id="mc-region-148" style="position: absolute; top: 3651pt; left: 138pt; width: 147.8pt; "><a name="" /><p class="Style1">Error in temperature measurement</p></div><div id="mc-region-149" style="position: absolute; top: 3667.8pt; left: 12pt; width: 38.4pt; "><a name="" /><img border="0" src=".\regression_images/IMG0039_17808877.PNG" id="generatedImage149" path=".\regression_images/IMG0039_17808877.PNG" style="width: 38.4pt;height: 28.2pt;"></img></div><div id="mc-region-154" style="position: absolute; top: 3729pt; left: 138pt; width: 117.8pt; "><a name="" /><p class="Style1">Error in each measurement</p></div><div id="mc-region-151" style="position: absolute; top: 3699pt; left: 12pt; width: 63pt; "><a name="" /><img border="0" src=".\regression_images/IMG0040_17808887.PNG" id="generatedImage151" path=".\regression_images/IMG0040_17808887.PNG" style="width: 63pt;height: 96.6pt;"></img></div><div id="mc-region-156" style="position: absolute; top: 3801pt; left: 12pt; width: 203pt; "><a name="" /><p class="Style1">Now we can plot error bars on logarithmic graph</p></div><div id="mc-region-157" style="position: absolute; top: 3824.4pt; left: 12pt; width: 78.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0041_17808887.PNG" id="generatedImage157" path=".\regression_images/IMG0041_17808887.PNG" style="width: 78.6pt;height: 13.2pt;"></img></div><div id="mc-region-159" style="position: absolute; top: 3842.4pt; left: 12pt; width: 79.8pt; "><a name="" /><img border="0" src=".\regression_images/IMG0042_17808897.PNG" id="generatedImage159" path=".\regression_images/IMG0042_17808897.PNG" style="width: 79.8pt;height: 13.2pt;"></img></div><div id="mc-region-160" style="position: absolute; top: 3876pt; left: 12pt; width: 396.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0044_17808907.PNG" id="generatedImage160" path=".\regression_images/IMG0044_17808907.PNG" style="width: 396.6pt;height: 331.2pt;"></img></div><div id="mc-region-162" style="position: absolute; top: 4215pt; left: 6pt; width: 120.8pt; "><a name="" /><p class="Style1">Format the graph as before.</p></div><div id="mc-region-165" style="position: absolute; top: 4257pt; left: 6pt; width: 156.2pt; "><a name="" /><p class="Style1">Now test the weighted mean function</p></div><div id="mc-region-168" style="position: absolute; top: 4278.6pt; left: 6pt; width: 153.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0045_17808917.PNG" id="generatedImage168" path=".\regression_images/IMG0045_17808917.PNG" style="width: 153.6pt;height: 29.4pt;"></img></div><div id="mc-region-169" style="position: absolute; top: 4323pt; left: 6pt; width: 49.2pt; "><a name="" /><img border="0" src=".\regression_images/IMG0046_17808927.PNG" id="generatedImage169" path=".\regression_images/IMG0046_17808927.PNG" style="width: 49.2pt;height: 12.6pt;"></img></div><div id="mc-region-170" style="position: absolute; top: 4341pt; left: 6pt; width: 57pt; "><a name="" /><img border="0" src=".\regression_images/IMG0047_17808937.PNG" id="generatedImage170" path=".\regression_images/IMG0047_17808937.PNG" style="width: 57pt;height: 12.6pt;"></img></div><div id="mc-region-177" style="position: absolute; top: 4365pt; left: 6pt; width: 372.8pt; "><a name="" /><p class="Style1">We can now use these figures to create a model for the tea temperature at any given time</p></div><div id="mc-region-178" style="position: absolute; top: 4389pt; left: 6pt; width: 102.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0048_17808947.PNG" id="generatedImage178" path=".\regression_images/IMG0048_17808947.PNG" style="width: 102.6pt;height: 12.6pt;"></img></div><div id="mc-region-182" style="position: absolute; top: 4434pt; left: 6pt; width: 390.6pt; "><a name="" /><img border="0" src=".\regression_images/IMG0050_17808957.PNG" id="generatedImage182" path=".\regression_images/IMG0050_17808957.PNG" style="width: 390.6pt;height: 307.2pt;"></img></div><div id="mc-region-184" style="position: absolute; top: 4761pt; left: 6pt; width: 407pt; "><a name="" /><p class="Style1">Of course, this model gives the logarithm of the difference between the temperature of the tea and the ambient surroundings. As an exercise create a model which gives the real temperature of the tea assuming an ambient temperature of 18 deg C</p></div><div></div></body></html>