{VERSION 4 0 "IBM INTEL NT" "4.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "" 0 24 0 0 255 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 257 "Helvetica" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "Helvetica" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 " " 1 18 255 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 260 "Helvetica" 1 14 128 0 0 1 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 262 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 263 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{PSTYLE "Norm al" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 } 1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 3 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Warning" 2 7 1 {CSTYLE "" -1 -1 "" 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "M aple Output" -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Output" -1 12 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Title" -1 256 1 {CSTYLE "" -1 -1 "Times " 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }1 1 0 0 12 12 1 0 1 0 2 2 19 1 } {PSTYLE "Author" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 8 8 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT 256 21 "Mth 351 Least Squares" }}{PARA 257 "" 0 "" {TEXT 259 43 "Mth 351 Fall 2001 Assignment 2. Due \+ Oct 29." }}{PARA 0 "" 0 "" {TEXT 260 25 "Oct 22 2001 Maple 5 and 6" }} {PARA 0 "" 0 "" {TEXT 257 16 "Bent E. Petersen" }}{PARA 0 "" 0 "" {TEXT 258 35 "Filename: 351f2001-assign-02-ls.mws" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 291 " A thermistor is a device which can be used as a temperature sensor sin ce its resistance to an electrical current changes with temperature. I t is necessary first to calibrate it. For a thermistor the theoretical relation between the absolute temperature T and the resistance R \+ is given by" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "R=A*exp(B/T); 1/T = a+b*log(R);" }}{PARA 11 "" 1 " " {XPPMATH 20 "6#/%\"RG*&%\"AG\"\"\"-%$expG6#*&%\"BGF'%\"TG!\"\"F'" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#/*&\"\"\"F%%\"TG!\"\",&%\"aGF%*&%\"bGF %-%#lnG6#%\"RGF%F%" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 147 "for certain constants a and b. In practice th e relation is not so tidy. The equation used in practice is the empiri cal Steinhart-Hart equation" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "1/T=a+b*log(R)+d*(log(R))^3; " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/*&\"\"\"F%%\"TG!\"\",(%\"aGF%*&% \"bGF%-%#lnG6#%\"RGF%F%*&%\"dGF%)F,\"\"$F%F%" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 454 "where R is measured \+ in Ohms. Now both R and T have a distinguished 0 point so we do \+ not need to worry about translation invariance, but it is hard to beli eve that ohms have some special physical significance. In other words \+ the form of the equation ought to be invariant under a change of units . Yet changing to kilo-ohms would introduce a log(R)^2 term. Indeed, to achieve scale invariance we need to add a log(R)^2 term from the beginning. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 156 "In general we are not in posession ot the actual resistance of the thermistor, but just some value proportional to it. Thus the scal e invariance is crucial." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 20 "If we do so, we have" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "eqn1:=S=a+b*log(R)+c *(log(R))^2+d*(log(R))^3;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%%eqn1G/ %\"SG,*%\"aG\"\"\"*&%\"bGF)-%#lnG6#%\"RGF)F)*&%\"cGF))F,\"\"#F)F)*&%\" dGF))F,\"\"$F)F)" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 93 "Here we let S = 1/T so we will have a linear rel ation to fit (linear in powers of log(R))." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 261 8 "Problem:" }{TEXT -1 421 " Your \+ assignment is to fit this equation (by the method of least squares) to some gritty measurements of actual themistors generously provided by \+ Erik Petersen. You should also examine c to see if it is relatively \+ small as would be required by the Steinhart-Hart model. You should als o do a least squares fit for the Steinhart-Hart model (even if it does n't make sense for our data) and graphically compare the results." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 169 "If you e lect to do the problem in Maple, everything you need is provided below - you just have to sort it out. If you elect to do it some other way, you are on your own." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 483 "The original data consists of an ADC value (voltage a cross the thermistor as measured by an analog to digital converter) an d the temperature in degrees Celsius. We add a bias of 32768 to the \+ ADC measurement to obtain a value proportional to the actual voltage d rop across the thermistor, which in turn is proportional to the resist ance. The idea is to provide the constants a, b, c, d for each therm istor so it can be used to determine temperatures directly from the AD C values. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 119 "The temperature will also have to be adjusted by adding 273.15 to the Celcius reading to convert it to absolute Kelvin." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "Sadj :=T->1/(T+273.15);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%%SadjGR6#%\"TG 6\"6$%)operatorG%&arrowGF(*&\"\"\"F-,&9$F-$\"&:t#!\"#F-!\"\"F(F(F(" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "Radj:=ADC->evalf(ADC+32768) ;" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%%RadjGR6#%$ADCG6\"6$%)operatorG %&arrowGF(-%&evalfG6#,&9$\"\"\"\"&oF$F1F(F(F(" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 292 "Note the evalf() he re is critical. Without it Maple will retain the exact (symbolic) valu es of log(R) for as long as possible in computing the least squares \+ fit.Whether you get an error message or a crash depends on the version of Maple, but you will not like what you get in either case." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 47 "T he data sets are for two different thermistors" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 262 10 "Data Set 1" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 65 "ADC1 raw:=[-29292,-25792,-22338,-18446,-15124,-11267,-7469,-3843];" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%(ADC1rawG7*!&#HH!&#zD!&QB#!&Y%=!&C^ \"!&n7\"!%pu!%VQ" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "T1raw:= [2.426,5.333,7.997,10.814,13.085,15.600,17.968,20.143];" }}{PARA 11 " " 1 "" {XPPMATH 20 "6#>%&T1rawG7*$\"%EC!\"$$\"%L`F($\"%(*zF($\"&93\"F( $\"&&38F($\"&+c\"F($\"&oz\"F($\"&V,#F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "R1:=map(Radj,ADC1raw);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%#R1G7*$\"%wM\"\"!$\"%wpF($\"&I/\"F($\"&AV\"F($\"&Ww\"F($\"&,:# F($\"&*HDF($\"&D*GF(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "S1: =map(Sadj,T1raw);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%#S1G7*$\"+FIwGO !#7$\"+lM)3f$F($\"+c\"eob$F($\"+dJd@NF($\"+aGj$\\$F($\"+jM?jMF($\"+ " 0 "" {MPLTEXT 1 0 65 "ADC2raw:=[- 29564,-26068,-22618,-18730,-15408,-11553,-7755,-4127];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%(ADC2rawG7*!&k&H!&og#!&=E#!&I(=!&3a\"!&`:\"!%bx! %FT" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 62 "T2raw:=[2.426,5.333, 7.997,10.814,13.085,15.600,17.968,20.143];" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%&T2rawG7*$\"%EC!\"$$\"%L`F($\"%(*zF($\"&93\"F($\"&&38 F($\"&+c\"F($\"&oz\"F($\"&V,#F(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "R2:=map(Radj,ADC2raw);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%#R 2G7*$\"%/K\"\"!$\"%+nF($\"&],\"F($\"&QS\"F($\">\"F($\"&:7#F($\"&8]#F ($\"&T'GF(" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "S2:=map(Sadj, T2raw);" }}{PARA 12 "" 1 "" {XPPMATH 20 "6#>%#S2G7*$\"+FIwGO!#7$\"+lM) 3f$F($\"+c\"eob$F($\"+dJd@NF($\"+aGj$\\$F($\"+jM?jMF($\"+ " 0 "" {MPLTEXT 1 0 52 "with(stats[fit]):with(stat s[statplots]):with(plots):" }}{PARA 7 "" 1 "" {TEXT -1 50 "Warning, th e name changecoords has been redefined\n" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 90 "I threw in some plotting \+ packages too in case you want to try some sophisticated plotting." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 69 "lsq:=(Rdata,Sdata)->leastsquare[[R,S],eqn1,\{a,b,c,d\}]([Rdata,S data]):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 145 "Our function lsq() returns an equation in S and R. W e would probably prefer a relation between the ADC values and the temp erature in Celsius." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "eqn_data1:=lsq(R1,S1):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "TC1:=ADC->-273.15+1/subs(R=ADC+32768.0,rh s(eqn_data1)):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 58 "Replace the colons by semicolons above to see the re sults." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 237 "At this point you may wish to plot TC1(ADC) for ADC from abou t -30000 to -4000. If you a calibrating the thermistors for a custom er you would probably give the customer a graph and also the values of the parameters a, b, c and d." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 170 "Now repeat the analysis for the second d ata set. Also fit the original Steinhart-Hart model. How well does you r least squares fit actually fit the original data? Discuss." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "29 2 0" 0 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }