Usage of Interpolation Macros 

advertisement
Usage of Interpolation Macros SinceExceldoesn'tallowsimplehelpfieldswhencodingamacroinVBAitissometimes
confusingastohowtousesomeoneelse'smacro.Let'strythisasanexplanation...
LinearInterpolation
Givenasetofxvsydata,thelinearinterpolationroutine,Interpolate,willfindan
appropriatevalueofyigivenavalueofxi.Theroutinewilldetermineifxiisinbetweenany
ofthexdatavalues.Ifitis,thenlinearinterpolationisperformedthefindthevalueofyi.If
itisbeforethefirstxvalue,thentheyivalueisdeterminedbyextrapolationofthefirsttwo
points;ifitisafterthelastxvalue,thentheyivalueisdeterminedbyextrapolationofthe
lasttwopoints.
Thefollowingshowspartofaspreadsheet.We’reinterestedindeterminingthesulfur
contentofanarrowfractionwhosecumulativeyieldatthemiddleoftheincrementis70
vol%.WewillassociatetheyielddataincellsH5:H12withthesulfurdataincellsS5:S12.
UsingtheInsert Functionmenucommandwillultimatelybringupthedialogueboxshown
asfollows.Inthiscasethevalue“70”isspecified(givingananswerof4.9).Acellreference
couldalsobespecified.
J.L.Jechura
‐1‐
March23,2013
DistillationInterpolation
Distillationdata(yieldvstemperature)shouldbeinterpolated/extrapolatedinsuchasway
astoguaranteean“S”shapedcurve.ThisisensuredintheInterpolate_DistCurveroutineby
transformingtheyielddatausingtheNORMSDIST&NORMSINVroutinesandthen
performinglinearinterpolation/extrapolationonthetransformeddata.
Thisroutineshouldonlybeusedforyieldvstemperatureandisnotappropriatefor
workingwithothertypesofdatasets.
You'llbestartingwithagivensetofcorrespondingtemperature&yieldvaluesfromwhich
youwanttoextractanewvalue.Theblockofcellsthatdesignatethegiventemperature
valueswillbepassedintothemacroasthevariable"degF_Data".Theblockofcellsthat
designatethegivencumulativeyielddatawillbepassedintothemacrosasthevariable
"pctYield_Data";thesevaluesaretobescaledfrom0to100.
Youwillbecallingthemacrotoeitherestimateayieldfromatemperaturevalueora
temperaturefromayieldvalue.Bothofthesecalculationscanbedoneusingthesame
macro.Ifyouinputatemperaturevaluetocalculateayield,associatethecellwiththe
temperaturevalueas"Value"&let"YieldInput"beFALSE(sinceyoudidnotinputayield
value);themacrowillinterpretValueasatemperature(in°F)&returnacumulativeyield.
Ifyouinputayieldvaluetocalculateatemperature,associatethecellwiththeyieldvalue
as"Value"&let"YieldInput"beTRUE(sinceyoudidinputayieldvalue);themacrowill
interpretValueasayield(in%,0to100)&returnatemperature(in°F).
Intheexampleabove,thedegF_DatavaluesareincellsB5:B12andthepctYield_Dataarein
F5:F12.Thefollowingshowsthedialogueboxtodeterminetheyieldat750°F;notethatthe
resultis48.8vol%.
J.L.Jechura
‐2‐
March23,2013
Thefollowingshowsthedialogueboxtodeterminethetemperaturecorrespondingtoa50
vol%yield;notethattheresultisat763.8°F.
J.L.Jechura
‐3‐
March23,2013
Download