You are on page 1of 290

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''*************************************'''''''''''
'''''''''''* *'''''''''''
'''''''''''* MacroBundle *'''''''''''
'''''''''''* *'''''''''''
'''''''''''*************************************'''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' NOTICE
' Two least squares macros of tis Macro!u"dle, L#1 a"d
' $L#1, wic %ave "o &ro'lems i" ()cel 200*, ca" mal+
' fu"ctio" i" ()cel 2010 'ecause it will misi"ter&ret
' tem as cell addresses, eve" tou% tey are "ot used
' i" co",u"ctio" wit a" equal si%".
'
' -" order to avoid suc &ro'lems, tey ave 'ee" re+
' rela'eled as L#I a"d $L#I, were te I si%"ifies .wit
' I"terce&t/. 0or te sa1e of symmetry, teir cou"ter+
' &arts L#0 a"d $L#0 (wic do "ot %ive suc &ro'lems
' 'ecause ()cel as "o row "um'er 0)ave also 'ee"
' re"amed L#O a"d $L#O res&ectively, wit te O for
' .trou% te Ori%i"/. Moreover, to 'e co"siste"t,
' 2rto0 a"d 2rto1, L#Multi0 a"d L#Multi1, as well as
' L#3oly0 a"d L#3oly1 ave also 'ee" ca"%ed to 2rtoO
' a"d 2rtoI, L#MultiO a"d L#MultiI, a"d L#3olyO a"d
' L#3olyI.
' -f you &refer to 1ee& your old Macro!u"dle, and wa"t to
' use ()cel 2010, you ca" readily ma1e tese ca"%es
' yourself usi"% te 0i"d fu"ctio".
' TABLE OF CONTENTS
' List of macros
' 3ur&ose
' $arra"ty
' 4o&yri%t
' -"stallatio"
' 5&dates
' Te macros
' LIST OF MACROS (i"cludi"% sort descri&tio"s)
' Error analysis macro6
' Propagation com&utes te &ro&a%atio" of u"certai"ty for
' a si"%le fu"ctio" of o"e or more i"de&e"de"t i"&ut
' &arameters wit 1"ow" sta"dard deviatio"s, or for
' mutually de&e"de"t &arameters wit a 1"ow" covaria"ce
' matri).
' Linear least suares macros6
' LS is a %e"eral least squares fitti"% routi"e for li"ear,
' &oly"omial, a"d multivariate fitti"%, assumi"% o"e
' de&e"de"t varia'le. L#2 forces te fit trou% te
' ori%i", L#- does "ot. Te out&ut &rovides te &arameter
' values, teir sta"dard deviatio"s, te sta"dard
' deviatio" of te fit to te fu"ctio", te covaria"ce
' matri), a"d (o&tio"ally) te matri) of li"ear
' correlatio" coefficie"ts.
' ELS &rovides least squares smooti"% a"d differe"tiatio"
' for a" equidista"t (i" te i"de&e"de"t varia'le) 'ut
' oterwise ar'itrary fu"ctio" usi"% a '#avit71y+8olay'
' movi"% &oly"omial fit. (L#fi)ed uses a fi)ed+order
' &oly"omial, (L#auto self+o&timi7es te order of te
' fitti"% &oly"omial as it moves alo"% te fu"ctio".
' !LS is te equivale"t of L# wit te i"clusio" of user+
' assi%"a'le wei%ts.
' "radeByS# com&utes te sta"dard deviatio"s of te fit #f
' for all &ossi'le com'i"atio"s a"d &ermutatio"s of
' u"wei%ted least squares fits of a user+s&ecified
' multivariate e)&ressio" of u& to si) terms.
' LSPoly a&&lies L# to &oly"omial fitti"% to a &oly"omial
' of %radually i"creasi"% order (u& to 19).
' LSMulti a&&lies L# to a" i"creasi"% "um'er of terms of a
' multivariate least squares a"alysis.
' LSPermute com&utes te sta"dard deviatio" of te fit for
' all &ossi'le &ermutatio"s of multivariate &arameters
' of u& to si) terms.
' Non$linear least suares macros6
' Sol%erAid &rovides u"certai"ty estimates (sta"dard
' deviatio"s a"d te covaria"ce matri)) for #olver+
' derived &arameter values.
' ColumnSol%er a&&lies #olver to colum"+or%a"i7ed data,
' a"d is es&ecially useful for i"verse i"ter&olatio"
' of al%e'raic fu"ctio"s.
' Sol%erScan lets #olver sca" a two+dime"sio"al array of
' &arameter values.
' :ote tat 'ot 4olum"#olver a"d #olver#ca" require tat
' #olver.)la 'e activated, as descri'ed i" sectio" 1.2.2.
' Trans#orm macros6

' FT is a %e"eral+&ur&ose 0ourier tra"sform macro for
' forward or i"verse 0ourier tra"sformatio" of 2;" data
' were " is a" i"te%er lar%er ta" 2.
' "a&or &rovides time+freque"cy a"alysis.
' Ort'o yields a 8ram+#cmidt orto%o"ali7atio"
' Con%olution and decon%olution macros6

' Con%ol%e &rovides %e"eral co"volutio".
' Con%ol%eFT yields co"volutio" 'ased o" 0ourier
' tra"sformatio".
' (econ%ol%e &rovides deco"volutio"< tis macro is "ot always
' a&&lica'le.
' (econ%ol%eFT yields deco"volutio" 'ased o" 0ourier
' tra"sformatio".
' (econ%ol%eIt &erforms iterative (va" 4ittert)
' deco"volutio". =eco"volve-t0 as "o co"strai"ts,
' =eco"volve-t1 assumes tat te fu"ctio" is everywere
' "o"+"e%ative.

' Calculus macros6

' Rom&erg &erforms Rom'er% i"te%ratio" of a fu"ctio" of a si"%le
' varia'le ) defi"ed eiter o" te s&readseet or i" a s&ecial
' fu"ctio" (quatio"()). Te calli"% macros are Rom'er%>uto,
' wic evaluates te fu"ctio" o" te s&readseet, a"d
' Rom'er%#&ecify, wic requires a user+s&ecified fu"ctio".
' Trape) &erforms a tra&e7oidal i"te%ratio" of a fu"ctio" of a
' si"%le varia'le ) defi"ed eiter o" te s&readseet or i" a
' s&ecial fu"ctio" (quatio"()). Te calli"% macros are
' Tra&e7>uto, wic evaluates te fu"ctio" o" te s&readseet,
' a"d Tra&e7#&ecify, wic requires a user+s&ecified fu"ctio".
' (eri% &erforms "umerical differe"tiatio" usi"% ce"tral
' differe"ci"%.
' (eri%* also &erforms "umerical differe"tiatio" usi"% ce"tral
' differe"ci"%, 'ut with a new, higher-accuracy algorithm.
' (eri%Scan a&&lies =eriv to %e"erate results for a ra"%e of
' =elta values.
' Semi$integrate ? semi$di##erentiate are two small macros for
' cyclic voltammetry assumi"% &la"ar diffusio".
' Mapper6

' Mapper %e"erates colored (or %ray+scale) two+dime"sio"al ma&s.
' 8radual ma&&er %e"erates colored (or %ray+scale) two+
' dime"sio"al ma&s wit %radually ca"%i"% colors.
' @+'a"d ma&&er %e"erates colored (or %ray+scale) two+
' dime"sio"al ma&s wit @ disti"ct 'a"ds.
' 1*+'a"d ma&&er %e"erates colored (or %ray+scale) two+
' dime"sio"al ma&s wit 1* disti"ct 'a"ds.
' Miscellaneous macros6

' ScanF creates a" array of values of tefu"ctio" 0(),y) a"d,
' o&tio"ally, of a" -soListi"% for co"tour ma&&i"% wit -soL.
' RootFinder fi"ds a si"%le root of a fu"ctio" 0()) of )
' 'y 'isectio".
' Mo%ie(emos lists te macros used i" sectio" 1.A.
' InsertMBTool&ar &rovides a tool'ar for easy access to te
' macros of te Macro!u"dle. :ote6 i" ()cel 200* te
' M!Tool'ar ca" o"ly 'e dis&layed i" te >dd+-"s ri''o".
' Remo%eMTTool&ar
' Tis 'u"dle also co"tai"s te "ecessary au)iliary su'rou+
' ti"es a"d fu"ctio"s, as well as some freesta"di"%
' fu"ctio"s suc as Lagrange for &oly"omial i"ter&olatio".
' 3ractical e)am&les of te a&&licatio" of tese macros or
' fu"ctio"s i" te most rece"t versio" of my 'oo1 Advanced
' Excel for scientific data analysis (B
rd
editio", >tla"tic
' >cademic 2012) will ofte" 'e me"tio"ed as AE+ followed
' 'y sectio" a"dCor &a%e "um'ers.
' P,RPOSE
' Te macros i" tis Macro!u"dle are &rimarily offered
' as e)am&les of macro writi"%. Tey ca" also 'e used as
' suc i" scie"tific data a"alysis. Moreover, tey ca"
' 'e modified 'y te user. >ll suc uses a"dCor
' modificatio"s are u"der te res&o"si'ility, a"d at te
' ris1, of te user, a"d are su',ect to te co"ditio"s
' s&ecified 'elow.
' COP-LEFT . ABSENCE OF !ARRANT-
' Te material i" tis Macro!u"dle is free software6 you
' ca" distri'ute it a"dCor modify it u"der te terms of
' te 8:5 8e"eral 3u'lic Lice"ce as &u'lised 'y te 0ree
' #oftware 0ou"datio", eiter versio" B of te Lice"se,
' or (at your o&tio") a"y later versio".
' Tis material is distri'uted i" te o&e tat it may 'e
' useful, 'ut $-TD25T >:E $>RR>:TE< witout eve" te
' im&lied warra"ty of M(R4D>:T>!-L-TE or 0-T:(## 02R >
' 3>RT-45L>R 35R32#(. #ee te 8:5 8e"eral 3u'lic Lice"se
' for more details.
' 3lease dow"load te 8:5 8e"eral 3u'lic Lice"se from te
' we'site tt&6Cwww.!owdoi".eduCFrdelevieCe)cella"eous,
' or see tt&6Cwww.%"u.or%Clice"ses.
' AC/NO!LE("EMENT
' $e" results o'tai"ed wit tese macros are commu"icated
' (orally, electro"ically, i" &ri"t, or oterwise), &lease
' ma1e refere"ce to teir source, so tat oters ca" lear"
' of teir availa'ility a"d useful"ess. Terefore &lease
' refer to te 'oo1 Ad%anced E0cel #or scienti#ic data
' analysis, were tese macros a"d fu"ctio"s are e)&lai"ed
' a"d illustrated,a"dCor to te we'site of te autor,
' 'ttp1223334&o3doin4edu25rdele%ie2e0cellaneous, from were
' tey ca" 'e dow"loaded.
' INSTALLATION
' Te macros i" tis Macro!u"dle are writte" i" G!> (Gisual
' !>#-4 for >&&licatio"s) a"d will "ot wor1 i" versio"s of
' ()cel &recedi"% ()cel H, 'ecause tose early versio"s did
' "ot use G!> as teir macro la"%ua%e. #ome may i"cor&orate
' features tat were "ot yet availa'le i" ()cel versio"s H
' a"d @H, a"d terefore may require some modificatio"s to
' ru" u"der tose versio"s. Tey were tested i" ()cel @*,
' 2000, a"d 200B, a"d a&&ear to wor1 equally well i" ()cel
' 200* a"d 2010. Dere we first descri'e te i"stallatio"
' &rocedure for ()cel @* a"d more rece"t versio"s, wic
' merely amou"ts to co&yi"% tat te)t i"to a" ()cel G!(ditor
' module. Tereafter we summari7e te sli%tly differe"t
' i"stallatio" &rocedure for ()cel H a"d @H.

' Dere is a ste&+'y+ste& accou"t of ow to do tis, for
' tose wo ave "ever do"e it. :ote tat almost all first
' s&readseet comma"ds were re"amed i" ()cel 200*, a"d "o
' lo"%er carry u"derli"ed letters to i"dicate teir sortcut
' 1ey com'i"atio"s. !ut most of tese sortcut 1ey com'i"a+
' tio"s still wor1, i"cludi"% tose sow" ere, wic is wy
' we ave "ot 'otered to %ive te "ew 200* comma"d "ames.
' #elect tis te)t wit (dit +I #elect >ll or >ltJ(L (Mac6
' 2&tJ(L) a"d co&y it to te cli&'oard wit 4trlJ4. 2&e"
' ()cel, te" o&e" te Gisual !asic (ditor wit Tools +I
' Macro +I Gisual !asic (ditor or wit >ltJ011 (Mac6
' 2&tJ011) were 011 de"otes te fu"ctio" 1ey 011. -" te
' G!(ditor tool'ar clic1 o" -"sert +I Module. Te" use
' 4trlJG to &aste te Macro!u"dle te)t i"to te module.
' ()it to te s&readseet wit >ltJ011 (Mac6 2&tJ011).
' #ave te macros wit te s&readseet (tis a&&e"s
' automatically wit earlier versio"s, 'ut requires s&ecial
' care wit ()cel 200*), or i" your 3erso"al.)ls file.
' 0or i"stallatio" i" ()cel H or ()cel @H, after ()cel
' as 'ee" o&e"ed, use -"sert +I Macro +I Module to o&e" a
' module, te" &aste te Macro!u"dle te)t from te cli&+
' 'oard i"to te module. :ote6 most 'ut "ot all of tese
' &ro%rams ave 'ee" tested to ru" &ro&erly i" ()cel H a"d
' ()cel @H, 'ut some of teir rece"t em'ellism"ts may "ot
' wor1, si"ce tey use more rece"tly i"troduced as&ects of
' G!>.
' $it te a'ove you will ave access to all macros of tis
' Macro!u"dle via >ltJ0K (Mac6 2&tJ0K). 0or more co"ve"ie"t
' access, i"stall te Macro!u"dle Tool'ar wit >ltJ0K
' (Mac6 2&tJ0K), te" dou'le+clic1 o" -"sertM!Tool'ar.
' Te Macro!u"dle Tool'ar ca" 'e saved wit your s&read+
' seet, a"d ca" 'e removed wit RemoveM!Tool'ar. Eou ca"
' customi7e te Tool'ar 'y removi"% macros from it a"dCor
' addi"% your ow" custom macros to it.
' -f you wa"t tese macros to 'e availa'le every time you
' o&e" a s&readseet, you ca" i"cor&orate tem i" te
' 3erso"al.)ls file, wic will te" 'e o&e"ed automatically
' we"ever ()cel is o&e"ed. Dowever, ma1e sure o"ly to &lace
' well+tested macros i" 3erso"al.)ls, a"d o"ly modify tem
' after you ta1e tem outside 3erso"al.)ls. > &oor i"struc+
' tio" duri"% macro develo&me"t, if tried i" 3erso"al.)ls,
' may %et it to 'a"% u&', i" wic case you may "eed e)&ert
' el& to e)tricate yourself.
' 2" a"y %ive" li"e, all te)t to te ri%t of a" a&ostro&e
' (suc as i" tis i"troductio") is co"sidered a comme"t,
' a"d is terefore i%"ored 'y te G!(ditor. 4o"seque"tly
' it is "ot "ecessary to remove tem. Te G!(ditor will
' also remove italics, 'oldfaci"%, a"d color.
' -f you wa"t to remove &art or all of te Macro!u"dle, %o
' to its G!(ditor module, i%li%t te &art(s) you wa"t to
' remove, a"d delete tem. -f you wa"t to u&date to a "ewer
' versio" of te Macro!u"dle, remove te old versio" (or,
' i" case you do"'t ave a 'ac1+u& co&y of it, move it to
' tem&orary stora%e u"til you ave cec1ed out its u&date),
' te" i"sert te "ew versio".
' T6E MACROS
' 4olor code used6 macros i" &lue,
' "o"+macro su'routi"es i" purple,
' fu"ctio"s i" &ro3n.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''*********************************'''''''''''''
'''''''''''''** **'''''''''''''
'''''''''''''** 3R23>8>T-2: **'''''''''''''
'''''''''''''** **'''''''''''''
'''''''''''''*********************************'''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 1B, =ec. 201B
' 35R32#(6
' Tis macro com&utes te &ro&a%ated sta"dard deviatio" i"
' a si"%le fu"ctio" 0 'ased o" : i"&ut &arameters, 'ased o"
' teir sta"dard deviatio"s or o" te corres&o"di"% covari+
' a"ce matri). $e" o"ly te sta"dard deviatio"s are %ive",
' te macro will assume tat te i"&ut &arameters are mutu+
' ally i"de&e"de"t. :o suc assum&tio" will 'e made we"
' te covaria"ce matri) is &rovided. 0or a si"%le i"&ut
' &arameter, tere is "o disti"ctio" 'etwee" te two a&+
' &roaces. 0or more ta" o"e i"&ut &arameter, te macro
' reco%"i7es wic of te two com&utatio"s to &erform
' 'ecause te sta"dard deviatio"s will 'e &rovided as a
' vector, wile te covaria"ce matri) as te form of a
' square data array. Te com&o"e"ts of te : 'y : covari+
' a"ce matri) are assumed to 'e i" te same order as tose
' of te : i"&ut &arameters.

' #5!R25T-:(#6

' Tis macro does "ot require a"y su'routi"es

' -:35T6

' Te : i"de&e"de"t i"&ut &arameter values must 'e &laced
' eiter i" a co"ti%uous row or i" a co"ti%uous colum".
' Tey must 'e :5M!(R#, i.e., tey ca""ot 'e formulas,
' i.e., equatio"s.
' Te 2R=(R of te i"&ut &arameters a"d of te sta"dard
' deviatio"s must 'e te same, 'ecause te (&artial)
' derivative of te fu"ctio" a"d te corres&o"di"% sta"dard
' deviatio" are com'i"ed strictly o" te 'asis of teir
' seque"tial order. Te same a&&lies to te covaria"ce
' matri) if tis is used i"stead.
' Te : sta"dard deviatio"s or te corres&o"di"% covaria"ce
' matri) ca" co"tai" eiter values or formulas.
' Te fu"ctio" must of course 'e a 05:4T-2:, 'ecause a
' "um'er ca""ot 'e differe"tiated. -t is 2L we" it refers
' to te fu"ctio", as lo"% as tat refere"ce will res&o"d
' to ca"%es i" te i"&ut &arameters.
' 25T35T6
' Te sta"dard deviatio" of te si"%le fu"ctio" 0 will 'e
' &laced directly to te ri%t of, or 'elow, tat fu"ctio",
' i" italics, &rovided tat tis cell is eiter u"occu&ied
' or its co"te"ts ca" 'e overwritte". 2terwise, te result
' will 'e dis&layed i" a messa%e 'o).

' 3R24(=5R(6

' -" order to start tis macro, call it. Tere is "o "eed
' to i%li%t a"yti"% 'eforea"d.

' Eou will see a" i"&ut 'o) i" wic to &lace (eiter
' 'y ty&i"% or 'y te 'i%li%t+a"d+clic1' metod) te
' address(es) of te i"&ut &arameter(s). >fter you ave
' e"tered tese, a seco"d i"&ut 'o) will request te
' addresses of eiter te sta"dard deviatio"s or te
' covaria"ce matri). Tese sould ave 'ee" arra"%ed i"
' te same order as te earlier+e"tered &arameters.
' 0i"ally, a tird i"&ut 'o) will as1 for te address of
' te fu"ctio". Te out&ut, te sta"dard deviatio" of te
' fu"ctio", will 'e &rovided eiter o" te s&readseet,
' or trou% messa%e 'o)(es).
' (M>M3L(6
' 5se of tis macro is illustrated starti"% i" sectio"s
' 2.K a"d 2.@ of >dva"ced ()cel.
' :2T>T-2:6

' v value of
' :6 te "um'er of i"&ut &arameters
' M6 si"%le i"&ut &arameter (for :N1)
' #6 te corres&o"di"%, si"%le sta"dard deviatio" of M
' Mi6 multi&le i"&ut &arameters (for :I1) :2T(6 TD(#(
' M5#T !( -: > #-:8L(, 42:T-8525# R2$ 2R 42L5M:
' #i6 sta"dard deviatio"s of te multi&le i"&ut &ara+
' meters. :2T(6 TD(#( M5#T !( -: > #-:8L(, 42:T-+
' 8525# R2$ 2R 42L5M:
' 4M6 te covaria"ce matri)
' 06 te si"%le fu"ctio" trou% wic te error(s)
' &ro&a%ate(s)
' G06 te &ro&a%ated varia"ce of te fu"ctio" 0
' #f6 te &ro&a%ated sta"dard deviatio" of fu"ctio" 0

' $e disti"%uis five cases6
' 4 N 1 o"e &arameter 3, o"e u"certai"ty 5
' 4 N 2 &arameters 3 a"d u"certai"ties 5 i" colum" format
' 4 N B &arameters 3 a"d u"certai"ties 5 i" row format
' 0or 4 N 1 to B, te u"certai"ty is te sta"dard deviatio"
' 4 N 9 &arameters 3 i" colum", u"certai"ty 5 i" matri)
' 4 N H &arameters 3 i" row, u"certai"ty 5 i" matri)
' 0or 4 N 9 or H, te u"certai"ty must 'e i" te form of
' a covaria"ce matri), i.e., te u"certai"ties are i"
' terms of varia"ces (te squares of te sta"dard
' deviatio"s) a"d covaria"ces (wic may 'e 7ero).
Su& Propagation()
=im 4 >s -"te%er '4ase selector
=im i >s -"te%er, , >s -"te%er, m >s -"te%er
=im "um'er >s -"te%er, L44Test >s -"te%er
=im " >s -"te%er 'Lar%er dime"sio" of
'i"&ut &arameter set
=im :40 >s -"te%er ':um'er of 4olum"s of out&ut 0u"ctio"
=im :43 >s -"te%er ':um'er of 4olum"s of i"&ut 3arameters
=im :45 >s -"te%er ':um'er of 4olum"s of te 5"certai"ty
'estimate
=im :R0 >s -"te%er ':um'er of Rows of out&ut 0u"ctio"
=im :R3 >s -"te%er ':um'er of Rows of i"&ut 3arameters
=im :R5 >s -"te%er ':um'er of Rows i" te 5"certai"ty
'estimate
=im v0 >s =ou'le, v00 >s =ou'le
=im v0i:ew >s =ou'le, v0:ew >s =ou'le
=im vM:ew >s =ou'le, v#0 >s =ou'le, v# >s =ou'le
=im vG0i >s =ou'le, vG0 >s =ou'le, vM >s =ou'le
=im v4M >s Garia"t, v4Mi >s Garia"t
=im v=el >s Garia"t, vMi:ew >s Garia"t
=im v#0i >s Garia"t, v#i >s Garia"t
=im vMi >s Garia"t
=im myRa"%e1 >s Ra"%e, myRa"%e2 >s Ra"%e, myRa"%eB >s Ra"%e
=im >"swer, 00ormula, Locatio"(qual#i%", 3rom&t, Title
=im M0u"ctio" 'OOOOO
>6
' #elect te i"&ut &arameter values of te fu"ctio"
3rom&t N PTe te i"&ut &arameter valuesP ? 4r(1B) ? Q
Pof te fu"ctio" are located i"6P
Title N P5"certai"ty 3ro&a%atio" -"&ut!o) 16 -"&utP Q
? P 3arameters P
#et myRa"%e1 N >&&licatio".-"&ut!o)(3rom&t, Title, Q
Ty&e6NK)
myRa"%e1.#elect
:R3 N #electio".Rows.4ou"t
:43 N #electio".4olum"s.4ou"t
' 4ec1 te i"&ut format
Locatio"(qual#i%" N 0
-f :R3 N 0 Te" ("d
-f :R3 RI 1 >"d :43 RI 1 Te"
Ms%!o) PTe i"&ut &arameter values sould 'eP ? 4r(1B) Q
? P&ut i" eiter a si"%le co"ti%uous row orP ? Q
4r(1B) ? Pi" a si"%le co"ti%uous colum". Try a%ai".P, Q
, P3ro&a%atio" of u"certai"tyP
8oTo >
(lse-f :R3 N 1 >"d :43 N 1 Te"
" N 1
vM N #electio".Galue ' dime"sio"i"% te array
00u"ctio" N #electio".0ormula ' dime"sio"i"% te array
Locatio"(qual#i%" N -"#tr(1, 00u"ctio", PNP)
-f Locatio"(qual#i%" N 1 Te" 8oTo !
(lse-f :R3 I 1 >"d :43 N 1 Te"
" N :R3
vMi N #electio".Galue ' dime"sio"i"% te array
00u"ctio" N #electio".0ormula ' dime"sio"i"% te array
v=el N #electio".Galue ' dime"sio"i"% te array
vMi:ew N #electio".Galue ' dime"sio"i"% te array
v#0i N #electio".Galue ' dime"sio"i"% te array
0or , N 1 To "
Locatio"(qual#i%" N -"#tr(1, 00u"ctio"(,, 1), PNP)
-f Locatio"(qual#i%" N 1 Te" 8oTo !
:e)t ,
(lse-f :43 I 1 >"d :R3 N 1 Te"
" N :43
vMi N #electio".Galue
00u"ctio" N #electio".0ormula ' dime"sio"i"% te array
v=el N #electio".Galue ' dime"sio"i"% te array
vMi:ew N #electio".Galue ' dime"sio"i"% te array
v#0i N #electio".Galue ' dime"sio"i"% te array
0or , N 1 To "
Locatio"(qual#i%" N -"#tr(1, 00u"ctio"(1, ,), PNP)
-f Locatio"(qual#i%" N 1 Te" 8oTo !
:e)t ,
("d -f
8oTo 4
!6
' 4ec1 tat te Pi"&ut &arameter valuesP
' i"deed o"ly co"tai" values, "o formulas
Ms%!o) PTe i"&ut &arameter values ca" o"ly P ? Q
Pco"tai" :5M!(R#P ? 4r(1B) ? Q
P"ot fu"ctio"s (i.e., a"yti"% starti"% P ? Q
Pwit a" equal si%".P ? 4r(1B) ? Q
P3lease re+e"ter te i"&ut &arameter G>L5(#.P
("d
' #elect te u"certai"ty estimates (sta"dard deviatio"s
' or covaria"ce matri)) of te i"&ut &arameters
46
3rom&t N P Te sta"dard deviatio"s, orP Q
? 4r(1B) ? Pte covaria"ce matri), of teP Q
? 4r(1B) ? P i"&ut &arameters are located i"6P
Title N P5"certai"ty 3ro&a%atio" -"&ut!o) 26 P Q
? P5"certai"ty estimatesP
#et myRa"%e2 N >&&licatio" Q
.-"&ut!o)(3rom&t, Title, Ty&e6NK)
myRa"%e2.#elect
:R5 N #electio".Rows.4ou"t
:45 N #electio".4olum"s.4ou"t
' Gerify tat te "um'er of &arameters
' matces tat of te u"certai"ty estimates
"um'er N :43 J :R3 + 1
-f :45 N :R5 Te"
-f (:45 J :R5) C 2 RI "um'er Te"
Ms%!o) PTe dime"sio" of te covaria"ce matri) doesP Q
? 4r(1B) ? P"ot matc te "um'er of i"&ut P Q
? P&arametersP
("d
("d -f
("d -f
-f :45 RI :R5 Te"
-f :45 J :R5 + 1 RI "um'er Te"
Ms%!o) PTe "um'er of u"certai"ty estimates doesP Q
? 4r(1B) ? P"ot matc te "um'er of i"&ut P Q
? P&arametersP
("d
("d -f
("d -f
' Gerify a"d cate%ori7e te i"&uts,
' te" read te u"certai"ties
-f :45 N 0 Te" ("d
-f " N 1 >"d :R5 N 1 >"d :45 N 1 Te"
4 N 1 'o"ly o"e i"&ut &arameter
v# N #electio".Galue
("d -f
-f " I 1 Te" 'multi&le i"&ut &arameters6

-f " N :R5 >"d :45 N 1 Te"
4 N 2 'te i"de&e"de"t &arameters a"d
'teir sta"dard deviatio"s are
'located i" si"%le colum"s
v#i N #electio".Galue
("d -f
-f " RI :R5 >"d :45 N 1 Te"
Ms%!o) PTe "um'er of e"tries i" te twoP Q
? 4r(1B) ? Pi"&ut colum"s must 'e te same.P, Q
, P3ro&a%atio" of u"certai"tyP
("d
("d -f

-f " N :45 >"d :R5 N 1 Te"
4 N B 'te i"de&e"de"t &arameters a"d
'teir sta"dard deviatio"s are
'located i" si"%le rows
v#i N #electio".Galue
-f " RI :45 >"d :R5 N 1 Te"
Ms%!o) PTe "um'er of e"tries i" te twoP Q
? 4r(1B) ? Pi"&ut rows must 'e te same.P, Q
, P3ro&a%atio" of u"certai"tyP
("d
("d -f
("d -f
-f " N :45 >"d " N :R5 Te"
'mutually de&e"de"t &arameters6

-f :43 RI :45 >"d :R3 RI :R5 Te"
Ms%!o) PTe "um'er of e"tries for te P Q
? Pu"certai"ties doesP ? 4r(1B) ? Q
P"ot matc te "um'er of i"&ut &arameters.P Q
, , P3ro&a%atio" of u"certai"tyP
("d
("d -f

-f " N :R3 >"d :43 N 1 Te"
4 N 9 'te de&e"de"t &arameters are located
'i" a si"%le colum" of : items, a"d
'te covaria"ce matri) is : 'y :
v4M N #electio".Galue
v4Mi N #electio".Galue
("d -f

-f " N :43 >"d :R3 N 1 Te"
4 N H 'te de&e"de"t &arameters are located
'i" a si"%le row of : items, a"d
'te covaria"ce matri) is : 'y :
v4M N #electio".Galue
v4Mi N #electio".Galue
("d -f
("d -f
("d -f
-f :45 I 1 >"d :R5 I 1 >"d :45 RI :R5 Te"
Ms%!o) PTe covaria"ce matri) as a"P ? Q
4r(1B) ? P i"correct dime"sio". Try a%ai".P, Q
, P3ro&a%atio" of u"certai"tyP
8oTo 4
("d -f
-f :45 I 1 >"d :R5 I 1 Te"
L44Test N 0
0or i N 1 To "
-f v4M(i, i) I 0.@@@@@ >"d Q
v4M(i, i) R 1.00001 Te" L44Test N L44Test J 1
:e)t i
-f L44Test N " Te"
>"swer N Ms%!o)(PEou a&&ear to ave e"tered teP Q
? 4r(1B) ? Parray of li"ear correlatio" P Q
? Pcoefficie"tsP ? 4r(1B) ? Prater ta" te P Q
? Pcovaria"ce matri).P ? 4r(1B) Q
? P=o you wa"t to correct te i"&utOP, Q
v'Ees:o, P3ro&a%atio" of u"certai"tyP)
-f >"swer N v'Ees Te" 8oTo >
("d -f
("d -f
' #elect te fu"ctio"
#et myRa"%eB N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe 05:4T-2: ("ot ,ust its value) is located i"6P, Title6N Q
P5"certai"ty 3ro&a%atio" -"&ut!o) B6 0u"ctio"P, Ty&e6NK)
myRa"%eB.#elect
:R0 N #electio".Rows.4ou"t
:40 N #electio".4olum"s.4ou"t
-f :R0 N 0 Te" ("d
-f :R0 N 1 >"d :40 N 1 Te"
v0 N #electio".Galue
("d -f
-f :R0 RI 1 2r :40 RI 1 Te"
Ms%!o) PTe &ro&a%atio" is com&uted o"ly for a #-:8L( P Q
? Pfu"ctio".P, , P3ro&a%atio" of u"certai"tyP
("d
("d -f
' Test a"d &re&are te default out&ut cell for te
' sta"dard deviatio" of te fu"ctio" 0
' 3lace te sta"dard deviatio" to te ri%t of te cell
' co"tai"i"% 0 for a si"%le i"&ut &arameter, or we" te
' i"&ut &arameters are i" a si"%le colum"
-f " N 1 2r :43 N 1 Te"
#electio".2ffset(0, 1).#elect
m N 0
v00 N #electio".Galue
-f (-s(m&ty(v00) 2r v00 N 0) Te"
m N m
(lse
m N m J 1
("d -f
#electio".2ffset(0, +1).#elect
("d -f
' 3lace te sta"dard deviatio" 'elow 0 we" te
' i"&ut &arameters are or%a"i7ed i" a si"%le row.
-f " I 1 >"d :R3 N 1 Te"
#electio".2ffset(1, 0).#elect
m N 0
v00 N #electio".Galue
-f (-s(m&ty(v00) 2r v00 N 0) Te"
m N m
(lse
m N m J 1
("d -f
#electio".2ffset(+1, 0).#elect
("d -f
>&&licatio".#cree"5&dati"% N 0alse
vG0 N 0
myRa"%e1.#elect
' 4om&ute a"d dis&lay te sou%t sta"dard deviatio" v#0
#elect 4ase 4
4ase 1
vM:ew N vM * 1.000001
#electio".Re&lace vM, vM:ew
myRa"%eB.#elect
v0:ew N #electio".Galue
myRa"%e1.#elect
#electio".Re&lace vM:ew, vM
v#0 N >'s(1000000 * (v0:ew + v0) * v# Q
C vM)

myRa"%eB.#elect
-f m I 0 Te"
>"swer N Ms%!o) Q
(PTe cell to te ri%t of te fu"ctio" is P Q
? P"ot em&ty.P ? 4r(1B) ? P4a" its co"te"ts P Q
? P'e overwritte"OP, v'Ees:o, P2verwriteOP)
-f >"swer N v'Ees Te" m N 0
("d -f
-f m N 0 Te"
#electio".2ffset(0, 1).#elect
#electio".0o"t.-talic N True
#electio".Galue N v#0
(lse
Ms%!o) PTe sta"dard deviatio" of te fu"ctio" is P, Q
, P3ro&a%atio" of u"certai"tyP ? v#0
("d -f
4ase 2
0or i N 1 To "
vMi:ew(i, 1) N vMi(i, 1) * 1.000001
#electio".-tem(i, 1).Re&lace vMi(i, 1), vMi:ew(i, 1)
myRa"%eB.#elect
v0i:ew N #electio".Galue
myRa"%e1.#elect
#electio".-tem(i, 1).Re&lace vMi:ew(i, 1), vMi(i, 1)
vG0i N 1000000 * (v0i:ew + v0) Q
* v#i(i, 1) C vMi(i, 1)
vG0 N vG0 J vG0i ; 2
:e)t i
v#0 N #qr(vG0)
myRa"%eB.#elect
-f m I 0 Te"
>"swer N Ms%!o) Q
(PTe cell to te ri%t of te fu"ctio" is P Q
? P"ot em&ty.P ? 4r(1B) ? P4a" its co"te"ts P Q
? P'e overwritte"OP, v'Ees:o, P2verwriteOP)
-f >"swer N v'Ees Te" m N 0
("d -f
-f m N 0 Te"
#electio".2ffset(0, 1).#elect
#electio".0o"t.-talic N True
#electio".Galue N v#0
(lse
Ms%!o) PTe sta"dard deviatio" of te fu"ctio" is P, Q
, P3ro&a%atio" of u"certai"tyP ? v#0
("d -f
4ase B
0or , N 1 To "
vMi:ew(1, ,) N vMi(1, ,) * 1.000001
#electio".-tem(1, ,).Re&lace vMi(1, ,), vMi:ew(1, ,)
myRa"%eB.#elect
v0i:ew N #electio".Galue
myRa"%e1.#elect
#electio".-tem(1, ,).Re&lace vMi:ew(1, ,), vMi(1, ,)
vG0i N 1000000 * (v0i:ew + v0) Q
* v#i(1, ,) C vMi(1, ,)
vG0 N vG0 J vG0i ; 2
:e)t ,
v#0 N #qr(vG0)
myRa"%eB.#elect
-f m I 0 Te"
>"swer N Ms%!o)(PTe cell 'elow te fu"ctio" is P Q
? P"ot em&ty.P ? 4r(1B) ? P4a" its co"te"ts 'e P Q
? Poverwritte"OP, v'Ees:o, P2verwriteOP)
-f >"swer N v'Ees Te" m N 0
("d -f
-f m N 0 Te"
#electio".2ffset(1, 0).#elect
#electio".0o"t.-talic N True
#electio".Galue N v#0
(lse
("d -f
4ase 9
0or i N 1 To "
vMi:ew(i, 1) N vMi(i, 1) * 1.000001
#electio".-tem(i, 1).Re&lace vMi(i, 1), vMi:ew(i, 1)
myRa"%eB.#elect
v0i:ew N #electio".Galue
myRa"%e1.#elect
#electio".-tem(i, 1).Re&lace vMi:ew(i, 1), vMi(i, 1)
v=el(i, 1) N 1000000 * (v0i:ew + v0) Q
C vMi(i, 1)
:e)t i
0or , N 1 To "
0or i N 1 To "
vG0 N vG0 J v=el(i, 1) Q
* v=el(,, 1) * v4M(i, ,)
:e)t i
:e)t ,
v#0 N #qr(vG0)

myRa"%eB.#elect
-f m I 0 Te"
>"swer N Ms%!o) Q
(PTe cell to te ri%t of te fu"ctio" is P Q
? P"ot em&ty.P ? 4r(1B) ? P4a" its co"te"ts P Q
? P'e overwritte"OP, v'Ees:o, P2verwriteOP)
-f >"swer N v'Ees Te" m N 0
("d -f
-f m N 0 Te"
#electio".2ffset(0, 1).#elect
#electio".0o"t.-talic N True
#electio".Galue N v#0
(lse
Ms%!o) PTe sta"dard deviatio" of te fu"ctio" is P, Q
, P3ro&a%atio" of u"certai"tyP ? v#0
("d -f
4ase H
0or i N 1 To "
vMi:ew(1, i) N vMi(1, i) * 1.000001
#electio".-tem(1, i).Re&lace vMi(1, i), vMi:ew(1, i)
myRa"%eB.#elect
v0i:ew N #electio".Galue
myRa"%e1.#elect
#electio".-tem(1, i).Re&lace vMi:ew(1, i), vMi(1, i)
v=el(1, i) N 1000000 * (v0i:ew + v0) Q
C vMi(1, i)
:e)t i
0or i N 1 To "
0or , N 1 To "
vG0 N vG0 J v=el(1, i) Q
* v=el(1, ,) * v4M(,, i)
:e)t ,
:e)t i
v#0 N #qr(vG0)

myRa"%eB.#elect
-f m I 0 Te"
>"swer N Ms%!o)(PTe cell 'elow te fu"ctio" is P Q
? P"ot em&ty.P ? 4r(1B) ? P4a" its co"te"ts 'e P Q
? Poverwritte"OP, v'Ees:o, P2verwriteOP)
-f >"swer N v'Ees Te" m N 0
("d -f
-f m N 0 Te"
#electio".2ffset(1, 0).#elect
#electio".0o"t.-talic N True
#electio".Galue N v#0
(lse
Ms%!o) PTe sta"dard deviatio" of te fu"ctio" is P, Q
, P3ro&a%atio" of u"certai"tyP ? v#0
("d -f
("d #elect
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''********************************''''''''''''''
'''''''''''''* *''''''''''''''
'''''''''''''* Linear Least Suares *''''''''''''''
'''''''''''''* *''''''''''''''
'''''''''''''********************************''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te macros L#- a"d L#2 set te i"&ut &arameter & for te
' su'routi"e Least#quares, wic i" tur" com&utes te i"di+
' vidual coefficie"ts or &arameters wit teir sta"dard
' deviatio"s, &lus te corres&o"di"% covaria"ce matri) 4M
' a"d te array of li"ear correlatio" coefficie"ts 44 for
' a" u"wei%ted least squares fit to data i" 2 or more
' colum"s. Moreover, it &rovides te sta"dard deviatio" #f
' of te over+all fit of te fu"ctio" to te data.
' 4olor codi"% is used to alert te user we" te i"divi+
' dual sta"dard deviatio"s are of te same order of ma%"i+
' tude as te corres&o"di"% coefficie"ts, a"d we" te
' i"de&e"de"t varia'les e)i'it si%"ifica"t colli"earity.
' Tis macro uses te traditio"al least squares al%oritm.
' $e" te L4 matri) i"dicates i% colli"earity, a"d you
' use ()cel 200B or a more rece"t versio", you may i"stead
' wa"t to use ()cel's ow" Li"(st or Re%ressio", wic are
' "ow 'ased o" SR=ecom&ositio". 2terwise use te #i"%ular
' Galue =ecom&ositio" macros i" Gol&i's Matri).)la. !ut
' "eiter of tese &rovides te covaria"ce matri), wic
' you may terefore ave to co"struct yourself usi"%
' #olver a"d #olver>id.
' Te i"&ut &arameter & N 1 starts a %e"eral u"wei%ted
' least squares fit to te data wile & N 0 forces te fit
' to &ass trou% te ori%i", i.e., it assumes tat y N 0
' for ) N 0.
' #5!R25T-:(#6
' Tis macro requires te su'routi"es Multi&ly, -"vert, a"d
' Tra"s&ose
' -:35T6
' Te i"&ut data must 'e or%a"i7ed i" colum"s, arra"%ed
' as follows. Te first colum" must co"tai" te de&e"de"t
' varia'le y. Te seco"d (a"d a"y su'seque"t) colum"(s)
' must co"tai" te i"de&e"de"t varia'le(s) ).
' 25T35T6
' Te macro la'els te coefficie"ts a"d sta"dard devi+
' atio"s, e)ce&t we" tere is "o s&ace availa'le for
' la'els 'ecause te first data colum" is at te left
' ed%e of te s&readseet.
' 4omme"t 'o)es are used6
' (1) to ide"tify te versio" "um'er, te data i"&ut ra"%e,
' te "um'er : of data &oi"ts, te "um'er 3 of ad,usta'le
' fitti"% &arameters, a"d date a"d time of te a"alysis<
' (2) to e)&lai" te color code used to war" te user a'out
' te relia'ility of te coefficie"t ai, 'y dis&layi"% a
' cate%orical measure of te a'solute value of te ratio of
' ai to its sta"dard deviatio" si< a"d
' (B) to e)&lai" te color code used to alert te user of
' i% colli"earity, a%ai" usi"% a crude cate%ori7atio".
' 3R24(=5R(6
' !efore calli"% te macro, ma1e sure tat te out&ut area
' (at mi"imum tree li"es 'elow te i"&ut data 'loc1) does
' "ot co"tai" valua'le data.
' -" order to start te &rocess, i%li%t te e"tire i"&ut
' data 'loc1, a"d call L#- or L#2.
' (M>M3L(#6
' 5se of tis macro is illustrated starti"% i" sectio"s
' 2.H a"d 2.@ of >dva"ced ()cel.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Te fu"ctio" of te followi"% two drivers is merely to
' set te value of o"e &arameter, &, equal to eiter o"e or
' 7ero, i" order to coose 'etwee" a %e"eral least squares
' fitti"% (& N 1) or o"e tat forces te curve trou% te
' ori%i" (& N 0).
Su& LSO() ' for a" u"wei%ted least squares
' fit trou% te ori%i"
=im 3 >s =ou'le
3 N 0
4all Least#quares(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& LSI() ' for a %e"eral u"wei%ted
' least squares fit
=im 3 >s =ou'le
3 N 1
4all Least#quares(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& LeastSuares(3)
=im 4Ma) >s Lo"%, i >s Lo"%, , >s Lo"%, ,, >s Lo"%
=im lcc4 >s -"te%er, lccR >s -"te%er, m >s -"te%er
=im : >s -"te%er, :: >s -"te%er, RMa) >s Lo"%
=im a >s =ou'le, S >s =ou'le, Root >s =ou'le
=im #f >s =ou'le, ##R >s =ou'le, varE >s =ou'le
=im =ata>rray >s Garia"t, 2ut&ut>rray >s Garia"t
=im lcc>rray >s Garia"t, v>rray >s Garia"t
=im v0>rray >s Garia"t, 4ell >s Garia"t
=im myRa"%e >s Ra"%e
=im a>, >4, a=, >"swer, >"swer, ,>"swer
=im !o)>ddress, my>ddress1, my>ddress2
=im '>rray, 't>rray
=im &>rray, &i>rray, q>rray
=im M>rray, M!>rray, )t>rray
=im E>rray, yt>rray
' =etermi"atio" of te array si7e
!e%i"6
RMa) N #electio".Rows.4ou"t
4Ma) N #electio".4olum"s.4ou"t
' -f area is "ot i%li%ted 'efore te macro is called
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, PLeast #quares 0itP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 tat te "um'er of colum"s is at least 2
-f 4Ma) R 2 Te"
Ms%!o) PTere must 'e at least two colum"s,P ? Q
4r(1B) ? Po"e for E, a"d o"e or more for M.P, Q
, PLeast #quares 0itP
("d
("d -f
' 4ec1 tat tere are more data ta" coefficie"ts
-f RMa) + 4Ma) + 3 J 1 RN 0 Te"
Ms%!o) P$it P ? RMa) ? P data, L#P ? 3 ? Q
P ca" o"ly deter+P ? 4r(1B) ? Pmi"e P ? RMa) + 1 ? Q
P least squares coefficie"ts.P ? 4r(1B) ? 4r(1B) Q
? P>dd more data, or reduce te re+P ? 4r(1B) ? Q
Pquested "um'er of coefficie"ts.P
("d
("d -f

' =ime"sio" te arrays6
Re=im '>rray(1 To 4Ma), 1 To 1) >s =ou'le
Re=im 't>rray(1 To 1, 1 To 4Ma)) >s =ou'le
Re=im lcc>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im &>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im &i>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im q>rray(1 To 4Ma), 1 To 1) >s =ou'le
Re=im v>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im v0>rray(1 To 4Ma) + 1 J 3, 1 To 4Ma) + 1 J 3) Q
>s =ou'le
Re=im M>rray(1 To RMa), 1 To 4Ma)) >s =ou'le
Re=im M!>rray(1 To RMa), 1 To 1) >s =ou'le
Re=im )t>rray(1 To 4Ma), 1 To RMa)) >s =ou'le
Re=im E>rray(1 To RMa), 1 To 1) >s =ou'le
Re=im yt>rray(1 To 1, 1 To RMa)) >s =ou'le
' Read te data>rray, te" fill y>rray a"d )>rray.
=ata>rray N #electio".Galue
a= N #electio".>ddress
0or i N 1 To RMa)
E>rray(i, 1) N =ata>rray(i, 1)
:e)t i
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, 1)) Te"
Ms%!o) PE+value(s) missi"%P, , PLeast #quares 0itP
("d
("d -f
:e)t i
0or , N 2 To 4Ma)
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, ,)) Te"
Ms%!o) PM+value(s) missi"%P, , PLeast #quares 0itP
("d
("d -f
:e)t i
:e)t ,
' 0ill te first colum" of )>rray wit 7eroes (for & N 0)
' or o"es (for & N 1), te rest wit te data i" te
' )+colum"(s)
0or i N 1 To RMa)
M>rray(i, 1) N 4='l(3)
:e)t i
0or , N 2 To 4Ma)
0or i N 1 To RMa)
M>rray(i, ,) N =ata>rray(i, ,)
:e)t i
:e)t ,
' 4om&ute ! N (M' M)P M' E , were ' or t de"ote
' tra"s&ositio", a"d P or i i"dicate i"versio"
' Te various arrays, teir "ames, a"d
' teir dime"sio"s (rows, colum"s) are6
' E N E>rray ( rMa), 1)
' M N M>rray ( rMa), cMa))
' M' N Mt>rray ( cMa), rMa))
' M' M N &>rray ( cma), cMa))
' (M' M)P N &i>rray ( cMa), cMa))
' M' E N q>rray ( cMa), 1)
' ! N !>rray ( cMa), 1)
4all Tra"s&ose(M>rray, RMa), 4Ma), )t>rray)
4all Multi&ly()t>rray, 4Ma), RMa), M>rray, 4Ma), &>rray)
4all -"vert(&>rray, 4Ma), &i>rray)
4all Multi&ly()t>rray, 4Ma), RMa), E>rray, 1, q>rray)
4all Multi&ly(&i>rray, 4Ma), 4Ma), q>rray, 1, '>rray)
' 4ec1 a%ai"st overwriti"% s&readseet data
m N 0
-f (3 N 0 >"d 4Ma) N 2) Te"
0or i N 1 To B
#electio".2ffset(1, 0).#elect
2ut&ut>rray N #electio".Galue
0or , N 1 To 4Ma)
-f -s(m&ty(2ut&ut>rray(RMa), ,)) Te"
m N m
(lse
m N m J 1
("d -f
:e)t ,
:e)t i
#electio".2ffset(+B, 0).#elect
-f m I 0 Te" >"swer N Ms%!o)(PTere are data i" te P Q
? Ptree li"es 'elow teP ? 4r(1B) ? Q
Pi"&ut data array. P ? P4a" tey 'e overwritte"OP, Q
v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te" ("d
(lse
0or i N 1 To 1 J 2 * (3 J 4Ma))
#electio".2ffset(1, 0).#elect
2ut&ut>rray N #electio".Galue
0or , N 1 To 4Ma)
-f -s(m&ty(2ut&ut>rray(RMa), ,)) Te"
m N m
(lse
m N m J 1
("d -f
:e)t ,
:e)t i
#electio".2ffset(+1 + 2 * (3 J 4Ma)), 0).#elect
-f m I 0 Te" >"swer N Ms%!o)(PTere are data i" te P Q
? 1 J 2 * (3 J 4Ma)) ? P li"es 'elow teP ? 4r(1B) ? Q
Pi"&ut data array. P ? P4a" tey 'e overwritte"OP, Q
v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te" ("d
("d -f
' Te additio"al arrays, "ames, a"d
' dime"sio"s (rows, colum"s) are6
' E' N Et>rray ( 1, rMa))
' !' N !t>rray ( 1, cMa))
' M ! N M!>rray ( rMa), 1)
' v N v>rray ( cMa), cMa))
4all Tra"s&ose(E>rray, RMa), 1, yt>rray)
4all Tra"s&ose('>rray, 4Ma), 1, 't>rray)
4all Multi&ly(M>rray, RMa), 4Ma), '>rray, 1, M!>rray)
' 4alculate ##R N #um(E + M') ; 2< te" com&ute te
' varia"ce of y as varE N ##RC(rMa)+cMa)+&J1)< a"d te
' covaria"ce matri) v>rray as G N (M'M)P times varE.
##R N 0
0or , N 1 To RMa)
##R N ##R J (E>rray(,, 1) + M!>rray(,, 1)) ; 2
:e)t ,
varE N ##R C (RMa) + 4Ma) + 3 J 1)
#f N #qr(>'s(varE))
0or i N 1 To 4Ma)
0or , N 1 To 4Ma)
v>rray(i, ,) N varE * &i>rray(i, ,)
:e)t ,
:e)t i

>&&licatio".#cree"5&dati"% N 0alse
>ctive4ell.2ffset(RMa), 0).#elect
' 3re&are te out&ut format
0or , N 1 To 4Ma)
>ctive4ell.0o"t.!old N True
>ctive4ell.0o"t.-talic N True
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
-f (3 N 0 >"d 4Ma) N 2) Te"
0or i N 1 To 2
0or , N 1 To 4Ma)
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N True
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
:e)t i
>ctive4ell.2ffset(+B, 0).#elect
(lse
0or i N 1 To 1 J 3 J 4Ma)
0or , N 1 To 4Ma)
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N True
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
:e)t i
>ctive4ell.2ffset(+2 + 3 + 4Ma), 0).#elect
("d -f
' 3re&are te out&ut la'els, su&&ressi"% tem we" s&ace
' for tem is u"availa'le or data will 'e overwritte"
a> N >ctive4ell.>ddress
>4 N Mid(a>, 1, B)
-f (>4 N PT>TP >"d 3 N 1) Te" 8oTo :oLa'el
>ctive4ell.2ffset(0, +3).#elect
-f 3 N 1 Te"
-f (-s(m&ty(>ctive4ell) 2r >ctive4ell.Galue N P4oeff6P) Q
Te"
8oTo #te&1
(lse
>ctive4ell.2ffset(0, 3).#elect
8oTo :oLa'el
("d -f
("d -f
#te&16 ' Ma1e la'el for 4oeff
$it >ctive4ell
.Galue N P4oeff6P
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
.Dori7o"tal>li%"me"t N )lRi%t
("d $it
>ctive4ell.2ffset(1, 0).#elect
-f 3 N 1 Te"
-f (-s(m&ty(>ctive4ell) 2r >ctive4ell.Galue N P#t=ev6P) Q
Te"
8oTo #te&2
(lse
>ctive4ell.2ffset(+1, 3).#elect
8oTo :oLa'el
("d -f
("d -f
#te&26 ' Ma1e la'el for #t=ev
$it >ctive4ell
.Galue N P#t=ev6P
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.-"terior.4olor-"de) N )l:o"e
.Dori7o"tal>li%"me"t N )lRi%t
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
PS N a's(3C#)< 4olors6P ? 4r(10) ? Q
P%ray6 B R S RN HP ? 4r(10) ? Q
Pora"%e6 2 R S RN BP ? 4r(10) ? Q
Pred6 1 R S RN 2P ? 4r(10) ? Q
P'old red6 S RN 1P
("d $it
>ctive4ell.2ffset(1, 0).#elect
-f 3 N 1 Te"
-f (-s(m&ty(>ctive4ell) 2r Q
>ctive4ell.Galue N P#f6P) Te"
8oTo #te&B
(lse
>ctive4ell.2ffset(+1, 3).#elect
8oTo :oLa'el
("d -f
("d -f
#te&B6 ' Ma1e la'el for #f
$it >ctive4ell
.Galue N P#f6P
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
.Dori7o"tal>li%"me"t N )lRi%t
("d $it
>ctive4ell.2ffset(+1, 3).#elect
-f 3 N 0 >"d 4Ma) N 2 Te"
>ctive4ell.2ffset(+1, 3).#elect
8oTo :oLa'el
("d -f
>ctive4ell.2ffset(B, +3).#elect
-f 3 N 1 Te"
-f (-s(m&ty(>ctive4ell) 2r Q
>ctive4ell.Galue N P4M6P) Te" 8oTo #te&9
(lse
>ctive4ell.2ffset(+B, 3).#elect
8oTo :oLa'el
("d -f
#te&96 ' Ma1e la'el for 4M
>ctive4ell.2ffset(+1, 0).#elect
$it >ctive4ell
.Galue N P4M6P
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N H
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
.Dori7o"tal>li%"me"t N )lRi%t
("d $it
>ctive4ell.2ffset(+B, 3).#elect
:oLa'el6
>ctive4ell.2ffset(0, 1 + 3).#elect
0or , N 2 + 3 To 4Ma)
$it >ctive4ell
.Galue N '>rray(,, 1)
.:um'er0ormat N P8e"eralP
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
.2ffset(0, 1).#elect
("d $it
:e)t ,
>ctive4ell.2ffset(1, 1 + 3 + 4Ma)).#elect
:: N 0
0or , N 2 + 3 To 4Ma)
>ctive4ell.0o"t.4olor-"de) N B
>ctive4ell.-"terior.4olor-"de) N )l:o"e
>ctive4ell.4lear4omme"ts
>ctive4ell.0o"t.!old N True

' $ar"i"% if varia"ce is 7ero or "e%ative

-f v>rray(,, ,) RN 0 Te"
$it >ctive4ell
.Galue N Pvar RN 0P
.0o"t.!old N True
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )l4e"ter
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
("d $it
:: N :: J 1
(lse
' =is&layi"% te sta"dard deviatio" i" color code6
' 'old red we" S RN 1
' red we" 1 R S RN 2
' ora"%e we" 2 R S RN B
' %ray we" B R S RN H
' 'lac1 we" S I H
>ctive4ell.Galue N #qr(v>rray(,, ,))
S N >'s('>rray(,, 1)) C #qr(v>rray(,, ,))
$it >ctive4ell.0o"t
-f S RN 1 Te"
.4olor-"de) N B ''old red
.!old N True
("d -f
-f S I 1 Te"
.4olor-"de) N B 'red
.!old N 0alse
("d -f
-f S I 2 Te" Q
.4olor-"de) N 9A 'ora"%e
-f S I B Te" Q
.4olor-"de) N 1A '%ray
-f S I H Te" Q
.4olor-"de) N 1 ''lac1
("d $it
("d -f
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
-f :: I 0 Te" Ms%!o) Q
PTis macro as difficulties wit te P ? Q
Pleast squares a"alysis.P ? 4r(1B) ? Q
P=istrust its "umerical a"swers. P ? Q
PEou may 'e a'le to solveP ? 4r(1B) ? Q
Ptis &ro'lem wit multivariate or P ? Q
P&oly"omial ce"teri"%. 2r,P ? 4r(1B) ? Q
Pif you use ()cel 200B or a P ? Q
Pmore rece"t versio", a"d youP ? 4r(1B) ? Q
Pdo "ot "eed te covaria"ce, P ? Q
Puse Li"(st or Re%ressio".P ? 4r(1B) ? Q
P2terwise, use )L# if you P ? Q
Pave M"um'ers.dll i"stalled,P ? 4r(1B) ? Q
Por svd &lus #olver>id if you ave P ? Q
PMatri).)la availa'le.P, 9K, P$ar"i"%UP
$it >ctive4ell
.2ffset(1, 1 + 3 + 4Ma)).#elect
.-"terior.4olor-"de) N )l:o"e
.:um'er0ormat N P8e"eralP
.4lear4omme"ts
("d $it
$it >ctive4ell
.Galue N #f
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )l4e"ter
.0o"t.4olor-"de) N 1
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
("d $it
>ctive4ell.2ffset(0, 1).#elect
>ctive4ell.2ffset(0, 1).#elect
$it >ctive4ell
.Galue N PP
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
("d $it
>ctive4ell.2ffset(0, +1).#elect
-f 3 N 0 >"d 4Ma) N 2 Te" >ctive4ell.2ffset(1, +1).#elect
$it >ctive4ell
.Galue N PL#P ? 3
.0o"t.!old N True
.0o"t.-talic N 0alse
.0o"t.4olor-"de) N H
.Dori7o"tal>li%"me"t N )l4e"ter
.-"terior.4olor-"de) N 20
.4lear4omme"ts
' -" a comme"t 'o), ide"tify te macro used, its
' o&tio"al &arameters, a"d its date ? time of use
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
PL#P ? 3 ? P versio" KP ? 4r(10) ? Q
P-"&ut6 P ? a= ? 4r(10) ? Q
P: N P ? RMa) ? P, 3 N P ? 4Ma) J 3 + 1 ? 4r(10) ? Q
Pdate N P ? =ate ? 4r(10) ? Ptime N P ? Time
("d $it
-f 3 N 0 >"d 4Ma) N 2 Te" >ctive4ell.2ffset(1, 0).#elect
>ctive4ell.2ffset(0, +1).#elect
' $rite te covaria"ce matri)
-f 3 N 0 >"d 4Ma) N 2 Te" 8oTo LastLi"e
>ctive4ell.2ffset(1, 0).#elect
0or i N 2 + 3 To 4Ma)
0or , N 2 + 3 To 4Ma)
$it >ctive4ell
.Galue N v>rray(i, ,)
.0o"t.4olor-"de) N H
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )l4e"ter
.:um'er0ormat N P8e"eralP
.-"terior.4olor-"de) N )l:o"e
.4lear4omme"ts
("d $it
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, 1 + 3 + 4Ma)).#elect
:e)t i
>&&licatio".#cree"5&dati"% N True

' 3rovide as o&tio"al out&ut te array of li"ear
' correlatio" coefficie"ts. Te user s&ecifies
' te cell 'loc1 i" wic to write tis array

-f 3 N 0 >"d 4Ma) N 2 Te" 8oTo LastLi"e
,>"swer N Ms%!o)(P=o you wa"t to see te P Q
? Pmatri) of li"ear correlatio"P Q
? 4r(1B) ? Pcoefficie"tsO -t will "eed a P Q
? P'loc1 of P ? 4Ma) J 3 + 1 Q
? P 'y P ? 4Ma) J 3 + 1 ? P cells.P, v'Ees:o, Q
PLeast #quares 0itP)
' Read locatio" of active cell
>ctive4ell.#elect
my>ddress1 N #electio".>ddress
>ctive4ell.2ffset(4Ma) J 3 + 2, 4Ma) J 3 + 2).#elect
my>ddress2 N #electio".>ddress
!o)>ddress N my>ddress1 ? P6P ? my>ddress2
>ctive4ell.2ffset(2 + 4Ma) + 3, 2 + 4Ma) + 3).#elect
2utli"eMatri)6

-f ,>"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
P#elect te default array locatio" wit 2L,P Q
? v'4r ? Poterwise ty&e i" your ow" coordi"ates6P, Q
=efault6N!o)>ddress, Ty&e6NK)
myRa"%e.#elect

' Ma1e sure tat te selected 'loc1 as te correct si7e

-f #electio".Rows.4ou"t RI 4Ma) J 3 + 1 Te"
Ms%!o) PTe selected ra"%e does "ot ave P Q
? 4Ma) J 3 + 1 ? P rows. 3lease correct.P, Q
, PLeast #quares 0itP
8oTo 2utli"eMatri)
("d -f
-f #electio".4olum"s.4ou"t RI 4Ma) J 3 + 1 Te"
Ms%!o) PTe selected ra"%e does "ot ave P Q
? 4Ma) J 3 + 1 ? P colum"s. 3lease correctP, Q
, PLeast #quares 0itP
8oTo 2utli"eMatri)
("d -f

>&&licatio".#cree"5&dati"% N 0alse

' =raw a 'o) arou"d te reserved area

#electio".!orders()l(d%eTo&).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%eTo&).$ei%t N )lTi"
#electio".!orders()l(d%eRi%t).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%eRi%t).$ei%t N )lTi"
#electio".!orders()l(d%e!ottom).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%e!ottom).$ei%t N )lTi"
#electio".!orders()l(d%eLeft).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%eLeft).$ei%t N )lTi"

' 0ormat cells i" array
0or (ac 4ell -" #electio".4ells
4ell.Dori7o"tal>li%"me"t N )l4e"ter
4ell.0o"t.4olor-"de) N 1
4ell.0o"t.!old N 0alse
4ell.0o"t.-talic N 0alse
4ell.-"terior.4olor-"de) N )l:o"e
4ell.4lear4omme"ts
:e)t 4ell
' $rite te array of li"ear correlatio" coefficie"ts

-f 3 N 0 Te"
0or i N 1 To 4Ma) + 1
0or , N 1 To 4Ma) + 1
v0>rray(i, ,) N v>rray(i J 1, , J 1)
:e)t ,
:e)t i
0or i N 1 To 4Ma) + 1
0or , N 1 To 4Ma) + 1
Root N #qr(v0>rray(i, i) * v0>rray(,, ,))
lcc>rray(i, ,) N v0>rray(i, ,) C Root
:e)t ,
:e)t i
#electio".Galue N lcc>rray
("d -f

-f 3 N 1 Te"
0or i N 1 To 4Ma)
0or , N 1 To 4Ma)
v0>rray(i, ,) N v>rray(i, ,)
:e)t ,
:e)t i
0or i N 1 To 4Ma)
0or , N 1 To 4Ma)
Root N #qr(>'s(v>rray(i, i) * v>rray(,, ,)))
lcc>rray(i, ,) N v>rray(i, ,) C Root
:e)t ,
:e)t i
#electio".Galue N lcc>rray
("d -f
("d -f
' 0ormat a"d color+code te cells i" te 44 array
' 4olor alerts i"dicati"% colli"earity6
' 'lac1 for a's(4oGar) R 0.@0
' %ray for 0.@0 RN a's(4oGar) R 0.@H
' ora"%e for 0.@H RN a's(4oGar) R 0.@K
' red for 0.@K RN a's(4oGar) R 0.@@
' 'old red for 0.@@ RN a's(4oGar) R 1
0or (ac 4ell -" #electio".4ells
4ell.Dori7o"tal>li%"me"t N )l4e"ter
4ell.0o"t.-talic N True
4ell.0o"t.!old N 0alse
a N >'s(4ell.Galue)
-f a R 0.@ Te"
4ell.0o"t.4olor-"de) N 1 ' 'lac1
(lse-f (a IN 0.@ >"d a R 0.@H) Te"
4ell.0o"t.4olor-"de) N 1A ' %ray
(lse-f (a IN 0.@H >"d a R 0.@K) Te"
4ell.0o"t.4olor-"de) N 9A ' ora"%e
(lse-f (a IN 0.@K >"d a R 0.@@) Te"
4ell.0o"t.4olor-"de) N B ' red
(lse-f a IN 0.@@ Te"
4ell.0o"t.!old N True ' 'old
4ell.0o"t.4olor-"de) N B ' red
("d -f
-f 4ell.Galue N 1 Te" 4ell.0o"t.-talic N 0alse
:e)t 4ell
' =o "ot color+code te mai" dia%o"al
lccR N #electio".Rows.4ou"t
lcc4 N #electio".4olum"s.4ou"t
0or i N 1 To lccR
0or , N 1 To lcc4
-f i N , Te"
#electio"(i, ,).0o"t.-talic N 0alse
#electio"(i, ,).0o"t.!old N 0alse
#electio"(i, ,).0o"t.4olor-"de) N 1
("d -f
:e)t ,
:e)t i
' La'el te li"ear correlatio" coefficie"ts
>ctive4ell.#elect
2" (rror Resume :e)t
>ctive4ell.2ffset(0, +1).#elect
-f (-s(m&ty(>ctive4ell) 2r Q
>ctive4ell.Galue N P446P) Te"
$it >ctive4ell
.Galue N P446P
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.-"terior.4olor-"de) N )l:o"e
.Dori7o"tal>li%"me"t N )lRi%t
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
P4olli"earity alerts6P ? 4r(10) ? Q
P%ray6 a's44 IN 0.@0P ? 4r(10) ? Q
Pora"%e6 a's44 IN 0.@HP ? 4r(10) ? Q
Pred6 a's44 IN 0.@KP ? 4r(10) ? Q
P'old red6 a's44 IN 0.@@P
("d $it
>ctive4ell.2ffset(0, 1).#elect
(lse
>ctive4ell.2ffset(0, 1).#elect
$it >ctive4ell
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
P4olli"earity alerts6P ? 4r(10) ? Q
P%ray6 a's44 IN 0.@0P ? 4r(10) ? Q
Pora"%e6 a's44 IN 0.@HP ? 4r(10) ? Q
Pred6 a's44 IN 0.@KP ? 4r(10) ? Q
P'old red6 a's44 IN 0.@@P
("d $it
("d -f
LastLi"e6

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''*************************************'''''''''''
'''''''''''* *'''''''''''
'''''''''''* Euidistant least suares *'''''''''''
'''''''''''* *'''''''''''
'''''''''''*************************************'''''''''''
''''''''''''''''''''' V 3. !ara1, &w'ara1Wfacstaff.wisc.edu
'''''''''''''''''''''''''''''''''''''' v H.B, Marc 1, 200H
' 35R32#(6
' Tis &ro%ram for a least+squares fit to (S5-=-#T>:T data
' y,) wit a movi"% &oly"omial uses te a&&roac &io"eered
' 'y 8ram, furter develo&ed 'y #e&&ard X3roc. Lo"do"
' Mat. #oc. (2) 1B (1@19) K1Y a"d #erriff X3roc. Royal
' #oc. (di"'ur% 90 (1@20) 112Y, a"d su'seque"tly advocated
' 'y $itta1er ? Ro'i"so" XTe calculus of o'servatio"s,
' !lac1ie ? #o", 1@29Y a"d 'y #avit71y ? 8olay X>"al. 4em.
' BA (1@A9) 1A2*Y. -t com&utes smooted values of te data
' set, or (if so desired) its first or seco"d derivative.
' Tere are two o&tio"s6 i" (L#fi)ed() te user also
' selects te order of te &oly"omial, wereas i" (L#auto()
' te &ro%ram o&timi7es te order of te &oly"omial ('et+
' wee" 1 a"d a" u&&er limit set 'y te user) eac time te
' movi"% &oly"omial slides o"e data &oi"t alo"% te data
' set, usi"% a" al%oritm descri'ed 'y !ara1 i" >"al. 4em.
' A* (1@@H) 2*HK.
' Te &ro%ram com&ares te ratio of te varia"ces for a
' %ive" order a"d tat for te "e)t+lower order wit te
' corres&o"di"% 0 test as its first criterio". #i"ce symme+
' trical fu"ctio"s ofte" co"tai" mostly eve" &owers, a
' si"%le, fi"al com&ariso" is made 'etwee" te varia"ces of
' te "e)t+i%er a"d te "e)t+lower order. -f te latter
' is "ot desired, sim&ly comme"t out te sectio" followi"%
' te comme"t li"e P#eco"d test for o&timum 2rderP.
' 05:4T-2:# ? #5!R25T-:(#6
' Tere are two drivers, (L#fi)ed a"d (L#auto, tat call
' te mai" su'routi"e, (L#(i2rder). Te latter uses te
' fu"ctio"s 8e"0act() a"d #moot(). -t also calls te su'+
' routi"e 4o"volutio"0actors, wic calculates te 8ram
' &oly"omials a"d te corres&o"di"% co"volutio" wei%ts.
' -:35T6
' Te user must select te movi"% &oly"omial le"%t< te
' corres&o"di"% value is restricted to odd i"te%ers 'etwee"
' B a"d B1. Tis coice i"volves a com&romise6 te lo"%er
' te &oly"omial, te more "oise is removed, a"d te more
' te u"derlyi"% si%"al is distorted. > useful rule of
' tum' is to ma1e te le"%t suc tat it e"com&asses "o
' more ta" te alf+widt of te most "arrow feature i"
' te si%"al tat sould 'e &reserved.
' Moreover, te le"%t of te movi"% &oly"omial, 3L, ca""ot
' e)ceed te le"%t of te data set, :3ts. Te selected
' (ma)imum) order of te &oly"omial, Ma)2rder, must 'e a
' &ositive i"te%er, Ma)2rderI0. Moreover, for (L#fi)ed,
' Ma)2rderR3L, wile for (L#auto we ave Ma)2rderR(3L+1).
' 25T35T6
' Te out&ut is writte" i" o"e or two colum"s to te ri%t
' of te i"&ut data. Te first out&ut colum" co"tai"s te
' smooted or differe"tiated data. Te seco"d colum", wic
' a&&ears o"ly wit (L#auto(), dis&lays te order selected
' 'y te &ro%ram. Ma1e sure tat te out&ut s&ace is free,
' or ca" 'e overwritte".
' (M>M3L(#6
' 5se of tis macro is illustrated i" sectio" B.1A of
' >(B.
' #ome of te a''reviatio"s a"d i"dices used6
' =er2rder6 te derivative order, selected 'y te
' a"swer to (L# -"&ut!o) 96 =erivative 2rder6
' =er2rder N 0 for smooti"%,
' =er2rder N 1 for te 1st derivative,
' =er2rder N 2 for te 2"d derivative.
' 0GalueTa'le6 te 0iser criterio", o'tai"ed
' from te ()cel fu"ctio" 0-"v.
' 836 te 8ram 3oly"omial
' ,6 i"de) for te order of te &oly"omial.
' 16 i"de) for te &ositio" of te ce"ter of te
' movi"% &oly"omial i" te data set<
' 1 ra"%es from mJ1 to :3ts+m.
' m6 "um'er of &oi"ts o" eac side of te ce"tral
' &oi"t i" te movi"% &oly"omial, calculated as
' m N (3L+1)C2.
' Ma)2rder6 te ma)imum order of te &oly"omial
' (from (L# -"&ut!o) B6 3oly"omial 2rder) or its
' ma)imum value (from (L# -"&ut!o) B6 Ma)imum 3oly+
' "omial 2rder). Ma)2rder must 'e a" i"te%er, I 0,
' a"d R 3L for (L#fi)ed, or R (3L+1) for (L#auto.
' :3ts6 "um'er of &oi"ts i" te data set, com&uted 'y
' te macro from te data ra"%e &rovided i" (L#
' -"&ut!o) 16 -"&ut data.
' 2&t2rder6 array of o&timi7ed 2rder values.
' 2rder6 wor1i"% value of te &oly"omial order.
' -" (L#fi)ed, 2rder N Ma)2rder< i" (L#auto, 2rder
' starts at 1, a"d as a ma)imum value of Ma)2rder.
' 2ut&ut=ata6 te fi"al (smooted or derivative) result
' 2ut&ut2rder6 te values of 2&t2rder used i" (L#auto.
' 3L6 le"%t (i" "um'er of &oi"ts) of te movi"% &oly+
' "omial, selected i" (L# -"&ut!o) 26 Le"%t of Mo+
' vi"% 3oly"omial.
' s6 i"de) for te order of te derivative< s ra"%es
' from 0 to =eriv2rder.
' t6 i"de) for te i"dividual &oi"ts i" te movi"%
' &oly"omial< t ra"%es from +m to Jm.
' tries6 "um'er of attem&ts to e"ter data i" i"&ut 'o)
' E() a"d E=ata()6 te i"&ut data co"tai"i"% te e"tire
' data set.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ELS#i0ed()
' #elects a fi)ed &oly"omial order
' 'y setti"% i2rder equal to 1
=im i2rder >s -"te%er
i2rder N 1
4all (L#(i2rder)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ELSauto()
' #elects a varia'le &oly"omial order ('etwee" 1 a"d a
' user+selecta'le ma)imum value,Ma)2rder) 'y setti"% i2rder
' equal to +1. :ote tat te i%+order &oly"omials may 'e
' u"desira'le for use wit, e.%., differe"tiatio" or i"ter+
' &olatio".
=im i2rder >s -"te%er
i2rder N +1
4all (L#(i2rder)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ELS(i2rder)
=im a >s -"te%er, ! >s -"te%er, =er2rder >s -"te%er
=im i >s -"te%er, ii >s -"te%er, , >s -"te%er
=im ,, >s -"te%er, 1 >s -"te%er, m >s -"te%er
=im Ma)2rder >s -"te%er, : >s -"te%er, :3ts >s -"te%er
=im 2rder >s -"te%er, 3L >s -"te%er, S >s -"te%er
=im s >s -"te%er, t >s -"te%er, Tries2 >s -"te%er
=im TriesB >s -"te%er, Tries9 >s -"te%er
=im 8e"0act >s =ou'le, 3erce"ta%e >s Lo"%
=im a> >s =ou'le, '' >s =ou'le, =eltaM >s =ou'le
=im 0Test1 >s =ou'le, 0Test2 >s =ou'le, Le"%t >s =ou'le
=im 3erc >s =ou'le, #um >s =ou'le, #um#q >s =ou'le
=im #umME >s =ou'le, #umE >s =ou'le, #umE2 >s =ou'le
=im 83() >s =ou'le, #um#quares() >s =ou'le
=im #umM2() >s =ou'le, w() >s =ou'le, E() >s =ou'le
=im 2&t2rder >s Garia"t, out&ut=ata >s Garia"t
=im 2ut&ut2rder >s Garia"t, Test4o"te"ts >s Garia"t
=im E=ata >s Garia"t
=im myRa"%e >s Ra"%e
=im >"s >s #tri"%
=im Z
' 3relimi"aries a"d data i"&ut
#et myRa"%e N Q
>&&licatio".-"&ut!o)(3rom&t6NPTe i"&ut data are P Q
? Plocated i" colum"6P, Q
Title6NP(L# -"&ut!o) 16 -"&ut dataP, Ty&e6NK)
myRa"%e.#elect
-f #electio".4olum"s.4ou"t RI 1 Te"
Ms%!o) P2"ly e"ter a si"%le colum" of i"&ut data.P
("d
("d -f
:3ts N #electio".Rows.4ou"t
-f :3ts N 0 Te" ("d
E=ata N myRa"%e.Galue
out&ut=ata N myRa"%e.Galue 'defi"es te array si7e
2ut&ut2rder N myRa"%e.Galue 'defi"es te array si7e
2&t2rder N myRa"%e.Galue 'defi"es te array si7e
' Test a"d &re&are te default out&ut ra"%e
: N 0
#electio".2ffset(0, 1).#elect
Test4o"te"ts N #electio".Galue
0or i N 1 To :3ts
Z N Test4o"te"ts(i, 1)
-f -s(m&ty(Z) Te"
: N :
(lse
: N : J 1
("d -f
:e)t i
-f i2rder N 1 Te"
-f : I 0 Te"
>"s N Ms%!o)(P Tere are data i" te P Q
? Pcolum" were te out&ut P ? 4r(1B) ? Q
Pwill 'e writte". 3roceed a"yway a"d overwrite P Q
? Ptose dataOP, v'Ees:o, Q
P(quidista"t Least #quares 0itP)
-f >"s N v':o Te"
Ms%!o) (P#afe%uard te data i" te i%li%ted P Q
? Parea 'yP ? 4r(1B) ? Pmovi"% tem to a"oter P Q
? P&lace, te" try a%ai".P), Q
, P(quidista"t Least #quares 0itP
("d
("d -f
("d -f
#electio".2ffset(0, +1).#elect
("d -f
-f i2rder N +1 Te"
#electio".2ffset(0, 1).#elect
Test4o"te"ts N #electio".Galue
0or i N 1 To :3ts
Z N Test4o"te"ts(i, 1)
-f -s(m&ty(Z) Te"
: N :
(lse
: N : J 1
("d -f
:e)t i
-f : I 0 Te"
>"s N Ms%!o)(PTere are data i" te T$2 colum"s P Q
? Pwere te out&ut P ? 4r(1B) ? Pwill 'e P Q
? Pwritte". 3roceed a"yway a"d overwrite P Q
? 4r(1B) ? Ptose dataOP, v'Ees:o, P(quidista"t P Q
? PLeast #quares 0itP)
-f >"s N v':o Te"
Ms%!o) (P#afe%uard te data i" te i%li%ted P Q
? Parea 'yP ? 4r(1B) ? Pmovi"% tem to a"oter P Q
? P&lace, te" try a%ai".P), Q
, P(quidista"t Least #quares 0itP
("d
("d -f
("d -f
#electio".2ffset(0, +2).#elect
("d -f
' #elect te le"%t of te movi"% &oly"omial, 3L
Tries2 N 0
Li"e26
Le"%t N -"&ut!o)(3rom&t6NPTe le"%t of te movi"% P Q
? P&oly"omial is6P, Q
Title6NP(L# -"&ut!o) 26 3oly"omial Le"%tP)
3L N 4-"t(Le"%t)
' Ma1e sure tat 3L is a" odd i"te%er
' lar%er ta" 0 a"d smaller ta" :3ts
-f (Le"%t RN 0 2r Le"%t IN :3ts 2r 3L + Le"%t RI 0 Q
2r 4-"t((3L + 1) C 2) + ((Le"%t + 1) C 2) RI 0) Te"
Ms%!o) PTe le"%t of te movi"% &oly"omial mustP ? Q
4r(1B) ? P 'e a" odd i"te%er lar%er ta" 7ero P Q
? Pa"d P ? 4r(1B) ? Psmaller ta" te le"%t of P ? Q
Pte i"&ut colum".P, , P(quidista"t Least #quares 0itP
Tries2 N Tries2 J 1
-f Tries2 N 2 Te" ("d
8oTo Li"e2
("d -f
' #elect te order of te movi"% &oly"omial, Ma)2rder
TriesB N 0
Li"eB6
-f i2rder N 1 Te"
Ma)2rder N -"&ut!o)(3rom&t6NPTe order of te movi"%P Q
? P&oly"omial is6P, Q
Title6NP(L# -"&ut!o) B6 3oly"omial 2rderP)
(lse
Ma)2rder N -"&ut!o)(3rom&t6NPTe ma)imum order of te P Q
? Pmovi"% &oly"omial is6P, Q
Title6NP(L# -"&ut!o) B6 3oly"omial 2rderP)
("d -f
' Ma1e sure tat Ma)2rder I 0 a"d tat eiter Ma)2rder R 3L
' (for (L#fi)ed) or Ma)2rder R 3L + 1 (for (L#auto).
-f i2rder N 1 Te"
-f (Ma)2rder RN 0 2r Ma)2rder IN 3L) Te"
Ms%!o) PTe order of te movi"% &oly"omialP ? 4r(1B) Q
? Pmust 'e lar%er ta" 7ero, a"d smallerP ? 4r(1B) Q
? Pta" te le"%t of te movi"% &oly"omial.P, , Q
P(quidista"t Least #quares 0itP
TriesB N TriesB J 1
-f TriesB N 2 Te" ("d
8oTo Li"eB
("d -f
(lse
-f (Ma)2rder RN 0 2r Ma)2rder IN 3L + 1) Te"
Ms%!o) PTe ma)imum order of te movi"% &oly"omialP ? Q
4r(1B) ? Pmust 'e lar%er ta" 7ero, a"d smaller P Q
? Pta"P ? 4r(1B) ? Pte le"%t of te movi"% P Q
? P&oly"omial mi"us 1.P, , Q
P(quidista"t Least #quares 0itP
TriesB N TriesB J 1
-f TriesB N 2 Te" ("d
8oTo Li"eB
("d -f
("d -f
' #elect smooti"%, first derivative, or seco"d derivative
Tries9 N 0
Li"e96
=er2rder N -"&ut!o)(3rom&t6NP#elect te order of te P Q
? PderivativeP ? 4r(1B) ? P(eiter 1 or 2)< for P Q
? Psmooti"%, select 0.P ? 4r(1B) ? 4r(1B) Q
? PTe order of te derivative is6P, Q
Title6NP(L# -"&ut!o) 96P ? P=erivative 2rderP)
' Ma1e sure tat =er2rder as te value 0, 1, or 2
-f =er2rder N 0 Te"
8oTo Li"eA
(lse-f =er2rder N 1 Te"
8oTo Li"eH
(lse-f =er2rder N 2 Te"
8oTo Li"eH
(lse
Ms%!o) P Te order of te movi"% &oly"omial must 'eP ? Q
4r(1B) ? Peiter 0 (for smooti"%), 1 (for te firstP Q
? 4r(1B) ? Pderivative), or 2 (for te seco"d P ? Q
Pderivative).P, , P(quidista"t Least #quares 0itP
Tries9 N Tries9 J 1
-f Tries9 N 2 Te" ("d
8oTo Li"e9
("d -f

Li"eH6
=eltaM N -"&ut!o)(3rom&t6NPTe data s&aci"% i" ) is6P, Q
Title6NP(L# -"&ut!o) H6 M -"creme"tP)
Li"eA6
m N (3L + 1) C 2
Re=im E(1 To :3ts), 2&t2rder(1 To :3ts, 1)
0or i N 1 To :3ts
E(i) N E=ata(i, 1)
2&t2rder(i, 1) N Ma)2rder
:e)t i
4all 4o"volutio"0actors(3L, Ma)2rder, =er2rder, 83, w, E)
' TD( 02LL2$-:8 #(4T-2: -# 5#(= 2:LE !E (L#auto
-f i2rder N +1 Te"
Re=im #umM2(1 To Ma)2rder)
0or , N 1 To Ma)2rder
#um N 0
0or i N +m To m
#um N #um J 83(i, ,, 0) ; 2
:e)t i
#umM2(,) N #um
:e)t ,
' 4alculate 0GalueTa'le(Ma)2rder,3L)
Re=im 0GalueTa'le(1 To Ma)2rder, 1 To 3L)
,, N 0
=o
,, N ,, J 1
0or ii N 1 To Ma)2rder
0GalueTa'le(ii, ,,) N >&&licatio".0-"v(0.0H, ii, ,,)
:e)t ii
Loo& 5"til ,, N 3L
0or 1 N m J 1 To :3ts + m

Re=im #um#quares(0 To Ma)2rder)
' 4alculate #um#quares for 2rder N 0
2rder N 0
#umE N 0
#umE2 N 0
0or t N +m To m
#umE N #umE J E(1 J t)
#umE2 N #umE2 J E(1 J t) ; 2
:e)t t
#um#quares(0) N #umE2 + #umE ; 2 C (2 * t J 1)
' 4alculate #um#quares for 2rder N 1
2rder N 1
#um#q N 0
0or t N +m To m
#um#q N #um#q J (#moot(3L, 1, 2rder, t, 0, w, E) Q
+ E(1 J t)) ; 2
:e)t t
#um#quares(1) N #um#q

' Test weter o"e+i%er order satisfies te criterio"
=o
2rder N 2rder J 1
-f 2rder I Ma)2rder Te" 8oTo li"e10

' 4alculate #um#quares for 2rder I 1
#umME N 0
0or t N +m To m
#umME N #umME J E(1 J t) * 83(t, 2rder, 0)
:e)t t
#um#quares(2rder) N #um#quares(2rder + 1) Q
+ #umME ; 2 C #umM2(2rder)

' 0irst test for o&timum 2rder
0Test1 N Q
(#um#quares(2rder + 1) + #um#quares(2rder)) * Q
(3L + 2rder) C (#um#quares(2rder))
Loo& 5"til Q
(0Test1 C 0GalueTa'le(1, 3L + 2rder + 1)) R 1
' #eco"d test for o&timum 2rder

-f 2rder R Ma)2rder Te"
2rder N 2rder J 1
#umME N 0
0or t N +m To m
#umME N #umME J E(1 J t) * 83(t, 2rder, 0)
:e)t t
#um#quares(2rder) N #um#quares(2rder + 1) Q
+ #umME ; 2 C #umM2(2rder)
0Test2 N Q
(#um#quares(2rder + 2) + #um#quares(2rder)) * Q
(3L + 2rder) C (#um#quares(2rder))
-f (0Test2 C 0GalueTa'le(2, 3L + 2rder + 1)) R 1 Q
Te" 2rder N 2rder + 1
("d -f
li"e106
2&t2rder(1, 1) N 2rder + 1

3erc N 100 * (1 C :3ts)
3erce"ta%e N -"t(3erc)
>&&licatio".#tatus!ar N Q
P4alculatio" P ? 3erce"ta%e ? P[ do"e.P

:e)t 1

("d -f
' TD-# (:=# TD( 3>RT 5#(= 2:LE !E (L#auto
' 3re&are te out&ut files
0or 1 N m J 1 To :3ts + m
-f 1 N m J 1 Te"
0or t N +m To +1
out&ut=ata(1 J t, 1) N Q
#moot(3L, 1, 2&t2rder(1 J t, 1), Q
t, =er2rder, w, E) C (=eltaM ; =er2rder)
2ut&ut2rder(1 J t, 1) N 2&t2rder(1, 1)
:e)t t
("d -f

out&ut=ata(1, 1) N Q
#moot(3L, 1, 2&t2rder(1, 1), 0, =er2rder, w, E) Q
C (=eltaM ; =er2rder)
2ut&ut2rder(1, 1) N 2&t2rder(1, 1)

-f 1 N :3ts + m Te"
0or t N 1 To m
out&ut=ata(1 J t, 1) N Q
#moot(3L, 1, 2&t2rder(1 J t, 1), Q
t, =er2rder, w, E) C (=eltaM ; =er2rder)
2ut&ut2rder(1 J t, 1) N 2&t2rder(1, 1)
:e)t t
("d -f
:e)t 1
' $rite te out&ut files
#electio".2ffset(0, 1).#elect
#electio".Galue N out&ut=ata
-f i2rder N +1 Te"
#electio".2ffset(0, 1).#elect
#electio".Galue N 2ut&ut2rder
#electio".2ffset(0, +1).#elect
("d -f

>&&licatio".#tatus!ar N 0alse
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function "enFact(a, !)
' 4om&utes te %e"erali7ed factorial
=im %f >s =ou'le, , >s -"te%er
%f N 1
0or , N (a + ! J 1) To a
%f N %f * ,
:e)t ,
8e"0act N %f
("d 0u"ctio"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pu&lic Function Smoot'(3L, 1, ,, t, s, w, E)
' 4om&utes te a&&ro&riately wei%ted sum of te E+values
=im i >s -"te%er, m >s -"te%er, #um >s =ou'le
m N (3L + 1) C 2
#um N 0
0or i N +m To m
#um N #um J w(i, t, ,, s) * E(1 J i)
:e)t i
#moot N #um
("d 0u"ctio"
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
Su& Con%olutionFactors(3L, Ma)2rder, =er2rder, 83, w, E)
' 4alculates ta'les of 83(i N +m to m, 1 N +1 to Ma)2rder,
' s N 1 to =er2rder), a"d of $(i N +m to m, t N +m to m,
' 1 N +1 to Ma)2rder, s N +1 to =er2rder)
' >''reviatio"s used6
' =er2rder6 =erivative 2rder
' 836 8ram 3oly"omial
' Ma)2rder6 Ma)imum 2rder,
' 3L6 3oly"omial Le"%t
' $6 $ei%t
=im i >s -"te%er, 1 >s -"te%er, m >s -"te%er
=im s >s -"te%er, t >s -"te%er
=im a> >s =ou'le, '' >s =ou'le
m N (3L + 1) C 2
Re=im 83(+m To m, +1 To Ma)2rder, +1 To =er2rder)
'(valuate te 8ram &oly"omials for =er2rderN0
0or i N +m To m
83(i, 0, 0) N 1
83(i, 1, 0) N 0
:e)t i
0or i N +m To +1
83(i, 1, 0) N i C m
:e)t i
0or i N 1 To m
83(i, 1, 0) N i C m
:e)t i
0or 1 N 2 To Ma)2rder
a> N 2 * (2 * 1 + 1) C (1 * (2 * m + 1 J 1))
'' N ((1 + 1) * (2 * m J 1)) C (1 * (2 * m + 1 J 1))
0or i N 0 To m
83(i, 1, 0) N a> * i * 83(i, 1 + 1, 0) + Q
'' * 83(i, 1 + 2, 0)
:e)t i
0or i N +m To +1
-f 1 Mod 2 N 0 Te"
83(i, 1, 0) N 83(+i, 1, 0)
(lse
83(i, 1, 0) N +83(+i, 1, 0)
("d -f
:e)t i
:e)t 1
'(valuate te 8ram &oly"omials for =er2rderI0
-f =er2rder I 0 Te"
0or s N 1 To =er2rder
0or i N +m To m
83(i, +1, s) N 0
83(i, 0, s) N 0
:e)t i
0or 1 N 1 To Ma)2rder
a> N 2 * (2 * 1 + 1) C (1 * (2 * m + 1 J 1))
'' N ((1 + 1) * (2 * m J 1)) C (1 * (2 * m + 1 J 1))
0or i N +m To m
83(i, 1, s) N a> * (i * 83(i, 1 + 1, s) J Q
s * 83(i, 1 + 1, s + 1)) + '' * 83(i, 1 + 2, s)
:e)t i
:e)t 1
:e)t s
("d -f
'4alculate te co"volutio" wei%ts
Re=im w(+m To m, +m To m, +1 To Ma)2rder, +1 To =er2rder)
0or 1 N 0 To Ma)2rder
a> N (2 * 1 J 1) * 8e"0act(2 * m, 1) C Q
8e"0act(2 * m J 1 J 1, 1 J 1)
0or s N 0 To =er2rder
0or i N +m To m
0or t N +m To m
w(i, t, 1, s) N w(i, t, 1 + 1, s) Q
J a> * 83(i, 1, 0) * 83(t, 1, s)
:e)t t
:e)t i
:e)t s
:e)t 1
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''*********************************''''''''''''''
''''''''''''* *''''''''''''''
''''''''''''* !eig'ted least suares *''''''''''''''
''''''''''''* *''''''''''''''
''''''''''''*********************************''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te macros L#- a"d L#2 set te i"&ut &arameter & for te
' su'routi"e Least#quares, wic i" tur" com&utes te i"di+
' vidual coefficie"ts or &arameters wit teir sta"dard
' deviatio"s, &lus te corres&o"di"% covaria"ce matri) 4M
' a"d te array of li"ear correlatio" coefficie"ts 44 for
' a" u"wei%ted least squares fit to data i" 2 or more
' colum"s. Moreover, it &rovides te sta"dard deviatio" #f
' of te over+all fit of te fu"ctio" to te data.
' 4olor codi"% is used to alert te user we" te i"divi+
' dual sta"dard deviatio"s are of te same order of ma%"i+
' tude as te corres&o"di"% coefficie"ts, a"d we" te
' i"de&e"de"t varia'les e)i'it si%"ifica"t colli"earity.
' Tis macro uses te traditio"al least squares al%oritm.
' $e" te L4 matri) i"dicates i% colli"earity, a"d you
' use ()cel 200B or a more rece"t versio", you may i"stead
' wa"t to use ()cel's ow" Li"(st or Re%ressio", wic are
' "ow 'ased o" SR=ecom&ositio". 2terwise use te #i"%ular
' Galue =ecom&ositio" macros i" Gol&i's Matri).)la. !ut
' "eiter of tese &rovides te covaria"ce matri), wic
' you may terefore ave to co"struct yourself usi"%
' #olver a"d #olver>id.
' Te i"&ut &arameter & N 1 starts a %e"eral u"wei%ted
' least squares fit to te data, wile & N 0 forces te fit
' to &ass trou% te ori%i", i.e., it assumes tat y N 0
' for ) N 0.
' #5!R25T-:(#6
' Tis macro requires te su'routi"es Multi&ly, GMulti&ly,
' -"vert, a"d Tra"s&ose
' :2T( R(8>R=-:8 GMulti&ly6
' Lo%ically, $L# sould i"volve a" (rMa) 'y rMa)) matri)
' co"tai"i"%, o" its mai" dia%o"al, te wei%ts assi%"ed
' to te various i"dividual measureme"ts, a"d wit 7eros
' everywere else. 0or lar%e values of rMa) tis matri)
' ca" readily 'ecome so lar%e as to slow dow" te macro.
' Terefore, te wei%ts ave i"stead 'ee" &laced i" a
' vector, $Gector, a"d te multi&licatio" &rocedure as
' 'ee" ad,usted accordi"%ly, i" te su'routi"e GMulti&ly.
' -:35T6
' Te i"&ut data must 'e or%a"i7ed i" colum"s, arra"%ed as
' follows. Te first colum" must co"tai" te de&e"de"t va+
' ria'le y. Te seco"d colum" sould co"tai" te wei%ts w
' of te i"dividual &oi"ts. Te tird (a"d a"y su'seque"t)
' colum"(s) must co"tai" te i"de&e"de"t varia'le(s) ).
' -f a" u"wei%ted least squares is desired, leave te
' wei%ts 'la"1, or e"ter te same "um'er (say, 1, or 1B)
' for all i"dividual wei%ts.
' =o :2T delete te seco"d colum", as i" tat case te
' macro will misi"ter&ret te i"&ut.
' 25T35T6
' Te macro la'els te coefficie"ts a"d sta"dard devia+
' tio"s, e)ce&t we" tere is "o s&ace availa'le for tem
' 'ecause te first data colum" is at te left ed%e of te
' s&readseet.
' -f te data to 'e a"aly7ed are te result of a tra"s+
' formatio" (suc as ta1i"% lo%aritms of a" e)&o"e"tial
' decay), te sta"dard deviatio" of te overall fit will
' "ot yield te correct a"swer wit res&ect to tose
' ori%i"al, u"tra"sformed data, 'ecause te macro does "ot
' read tose data. -f tat sta"dard deviatio" is desired,
' it is 'est com&uted se&arately o" te s&readseet.
' 4omme"t 'o)es are used6
' (1) to ide"tify te versio" "um'er, te data i"&ut ra"%e,
' te "um'er : of data &oi"ts, te "um'er 3 of ad,usta'le
' fitti"% &arameters, a"d date a"d time of te a"alysis<
' (2) to e)&lai" te color code used to war" te user a'out
' te relia'ility of te coefficie"t ai, 'y dis&layi"% a
' cate%orical measure of te a'solute value of te ratio of
' ai to its sta"dard deviatio" si< a"d
' (B) to e)&lai" te color code used to alert te user of
' i% colli"earity, a%ai" usi"% a crude cate%ori7atio".
' 3R24(=5R(6
' !efore calli"% te macro, ma1e sure tat te out&ut area
' is free of valua'le data. To fi"d out te reac of te
' out&ut, try out te macro 'ut, i" te P2verwriteOP
' messa%e 'o), "ote te "um'er of rows required, a"swer
' P:oP to weter te data ca" 'e overwritte", move te
' se"sitive data, te" try te macro a%ai".
' -" order to start te &rocess, i%li%t te e"tire i"&ut
' data 'loc1, te" call $L#- or $L#2.
' (M>M3L(#6
' 5se of tis macro is illustrated starti"% i" sectio"s
' B.1* trou% B.20 of >(B.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' :2T>T-2:6
' Tis su'routi"e com&utes te &arameters a"d teir
' sta"dard deviatio"s for a wei%ted or u"wei%ted least
' squares fit to data i" B or more colum"s. Te colum"s
' must 'e arra"%ed as follows6
' Te first colum" must co"tai" te de&e"de"t varia'le y.
' Te seco"d colum" must co"tai" te wei%ts w for y. 0or
' a" u"wei%ted least squares fit, leave tis colum" 'la"1,
' or fill it wit o"es, 'ut do "ot omit it. Te tird (a"d
' &ossi'ly su'seque"t) colum"(s) must co"tai" te i"de&e"+
' de"t varia'le(s) ).
' Te su'routi"e requires a" i"&ut &arameter &6 & N 1
' causes a %e"eral wei%ted least squares fit to te data,
' wile & N 0 forces te fit to &ass trou% te ori%i",
' i.e., it assumes tat E N 0 for M N 0. Te su'routi"e is
' terefore called 'y a driver ($L#2 or $L#-) tat sets te
' value of &.
Su& !LSO() ' for least squares fit
' trou% te ori%i"
=im 3 >s =ou'le
3 N 0
4all $ei%tedLeast#quares(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& !LSI() ' for %e"eral least squares fit
=im 3 >s =ou'le
3 N 1
4all $ei%tedLeast#quares(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& !eig'tedLeastSuares(3)
=im ccMa) >s -"te%er, 4Ma) >s -"te%er
=im , >s -"te%er, m >s -"te%er, : >s -"te%er
=im i >s Lo"%, RMa) >s Lo"%
=im Root >s =ou'le, ##R >s =ou'le, #t=ev0 >s =ou'le
=im sum$ >s =ou'le, u >s =ou'le, varE >s =ou'le
=im =ata>rray >s Garia"t, 2ut&ut>rray >s Garia"t
=im lcc>rray >s Garia"t
=im v>rray >s Garia"t, v0>rray >s Garia"t
=im myRa"%e >s Ra"%e
=im >"swer, >"swer, i>"swer, ,>"swer, 1>"swer
=im !o)>ddress, my>ddress1, my>ddress2
=im '>rray, 't>rray, 'tq>rray
=im &>rray, &i>rray, q>rray, $Gector
=im M>rray, )t>rray, E>rray, yt>rray, yty>rray
' =etermi"atio" of te array si7e6
!e%i"6
RMa) N #electio".Rows.4ou"t
4Ma) N #electio".4olum"s.4ou"t
ccMa) N 4Ma) + 1
u N 1
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, P$ei%ted Least #quaresP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 tat te "um'er of colum"s is at least B6
-f 4Ma) R B Te"
Ms%!o) PTere must 'e at least tree colum"s, o"eP ? Q
4r(1B) ? Pfor E, o"e for $, a"d o"e or more for M.P, Q
, P$ei%ted Least #quares 0itP
("d
("d -f
' 4ec1 tat tere are more data ta" coefficie"ts 6
-f RMa) + 4Ma) + 3 J 2 RN 0 Te"
Ms%!o) P$it P ? RMa) ? P data, $L#P ? 3 ? P ca" o"ly deter+P ?
Q
4r(1B) ? Pmi"e P ? RMa) + 1 ? P least squares coefficie"ts.P
? Q
4r(1B) ? 4r(1B) ? P>dd more data, or reduce te re+P ? Q
4r(1B) ? Pquested "um'er of coefficie"ts.P
("d
("d -f
' =ime"sio" te arrays6
Re=im E>rray(1 To RMa), 1 To 1) >s =ou'le
Re=im $Gector(1 To RMa)) >s =ou'le
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
Re=im yt>rray(1 To 1, 1 To RMa)) >s =ou'le
Re=im ytw>rray(1 To 1, 1 To RMa)) >s =ou'le
Re=im ytwy>rray(1 To 1, 1 To 1) >s =ou'le
Re=im )t>rray(1 To ccMa), 1 To RMa)) >s =ou'le
Re=im )tw>rray(1 To ccMa), 1 To RMa)) >s =ou'le
Re=im &>rray(1 To ccMa), 1 To ccMa)) >s =ou'le
Re=im &i>rray(1 To ccMa), 1 To ccMa)) >s =ou'le
Re=im q>rray(1 To ccMa), 1 To 1) >s =ou'le
Re=im '>rray(1 To ccMa), 1 To 1) >s =ou'le
Re=im 't>rray(1 To 1, 1 To ccMa)) >s =ou'le
Re=im 'tq>rray(1 To 1, 1 To 1) >s =ou'le
Re=im v>rray(1 To ccMa), 1 To ccMa)) >s =ou'le
Re=im v0>rray(1 To ccMa) J 3 + 1, 1 To ccMa) J 3 + 1) Q
>s =ou'le
Re=im lcc>rray(1 To ccMa) J 3 + 1, 1 To ccMa) J 3 + 1) Q
>s =ou'le
' Read te data>rray
=ata>rray N #electio".Galue
' 0ill E>rray
0or i N 1 To RMa)
E>rray(i, 1) N =ata>rray(i, 1)
:e)t i
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, 1)) Te"
Ms%!o) PE+value(s) missi"%P, Q
, P$ei%ted Least #quaresP
("d
("d -f
:e)t i
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, 2)) Te" =ata>rray(i, 2) N u
:e)t i
0or , N B To 4Ma)
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, ,)) Te"
Ms%!o) PM+value(s) missi"%P, Q
, P$ei%ted Least #quaresP
("d
("d -f
:e)t i
:e)t ,
' 0ill wGector wit te i"dividual, "ormali7ed wei%ts.
sum$ N 0
0or i N 1 To RMa)
sum$ N sum$ J =ata>rray(i, 2)
:e)t i
0or i N 1 To RMa)
$Gector(i) N =ata>rray(i, 2) * RMa) C sum$
:e)t i
' 0ill te first colum" of M>rray wit 7eroes (for & N 0)
' or o"es (for & N 1), te rest wit te data i" te
' )+colum"(s)
0or i N 1 To RMa)
M>rray(i, 1) N 3
:e)t i
0or , N B To 4Ma)
0or i N 1 To RMa)
M>rray(i, (, + 1)) N =ata>rray(i, ,)
:e)t i
:e)t ,
' 4om&ute ' N (M' $ M)P M' $ E , were ' or t de"ote
' tra"s&ositio", a"d P or i i"dicate i"versio"
' Te various arrays a"d teir dime"sio"s (rows, colum"s)
' are6
' E N y>rray ( rMa), 1)
' $ N wGector ( rMa))
' M N )>rray ( rMa), ccMa))
' M' N )t>rray ( ccMa), rMa))
' M' $ N )tw>rray ( ccMa), rMa))
' M' $ M N &>rray ( ccMa), ccMa))
' (M' $ M)P N &i>rray ( ccMa), ccMa))
' M' $ E N q>rray ( ccMa), 1)
' ' N '>rray ( ccMa), 1)
4all Tra"s&ose(M>rray, RMa), ccMa), )t>rray)
4all GMulti&ly()t>rray, ccMa), RMa), $Gector, )tw>rray)
4all Multi&ly()tw>rray, ccMa), RMa), M>rray, ccMa), &>rray)
4all -"vert(&>rray, ccMa), &i>rray)
4all Multi&ly()tw>rray, ccMa), RMa), E>rray, 1, q>rray)
4all Multi&ly(&i>rray, ccMa), ccMa), q>rray, 1, '>rray)
' 4ec1 a%ai"st overwriti"% s&readseet data
#electio".2ffset(2, 0).#elect
2ut&ut>rray N #electio".Galue
#electio".2ffset(+2, 0).#elect
m N 0
-f (3 N 0 >"d 4Ma) N B) Te"
0or i N 1 To B
#electio".2ffset(1, 0).#elect
2ut&ut>rray N #electio".Galue
0or , N 1 To 4Ma)
-f -s(m&ty(2ut&ut>rray(RMa), ,)) Te"
m N m
(lse
m N m J 1
("d -f
:e)t ,
:e)t i
#electio".2ffset(+B, 0).#elect
-f m I 0 Te" >"swer N Ms%!o)(PTere are data i" te P Q
? Ptree li"es 'elow teP ? 4r(1B) ? Q
Pi"&ut data array. P ? P4a" tey 'e overwritte"OP, Q
v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te" ("d
(lse
0or i N 1 To B J 3 J 4Ma)
#electio".2ffset(1, 0).#elect
2ut&ut>rray N #electio".Galue
0or , N 1 To 4Ma)
-f -s(m&ty(2ut&ut>rray(RMa), ,)) Te"
m N m
(lse
m N m J 1
("d -f
:e)t ,
:e)t i
#electio".2ffset(+B + 3 + 4Ma), 0).#elect
-f m I 0 Te" >"swer N Ms%!o)(PTere are data i" te P Q
? 1 J 3 J 4Ma) ? P li"es 'elow teP ? 4r(1B) ? Q
Pi"&ut data array. P ? P4a" tey 'e overwritte"OP, Q
v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te" ("d
("d -f
' Te additio"al arrays a"d teir dime"sio"s (rows,
' colum"s) are6
' E' N yt>rray ( 1, rMa))
' E' $ N ytw>rray ( 1, rMa))
' E' $ E N ytwy>rray ( 1, 1)
' '' N 't>rray ( 1, ccMa))
' '' M' $ E N 'tq>rray ( 1, 1)
4all Tra"s&ose(E>rray, RMa), 1, yt>rray)
4all Tra"s&ose('>rray, ccMa), 1, 't>rray)
4all GMulti&ly(yt>rray, 1, RMa), $Gector, ytw>rray)
4all Multi&ly(ytw>rray, 1, RMa), E>rray, 1, ytwy>rray)
4all Multi&ly('t>rray, 1, ccMa), q>rray, 1, 'tq>rray)
' 4alculate ##R N E'$E + ''M'$E, a"d te" varE, te vari+
' a"ce of y, as varE N ##RC(rma)+ccma))< a"d v>rray, te
' covaria"ce matri), as G N (M'$M)P times varE, of wic
' we ere o"ly use te dia%o"al eleme"ts, i.e., te vari+
' a"ces.
##R N ytwy>rray(1, 1) + 'tq>rray(1, 1)
varE N ##R C (RMa) + ccMa) + 3 J 1)
-f ##R IN 0 Te" #t=ev0 N #qr(varE)
-f ##R R 0 Te"
#t=ev0 N #qr(+varE)
Ms%!o) P##R is P ? ##R ? P, wic is "e%ativeUP
("d -f
0or i N 1 To ccMa)
0or , N 1 To ccMa)
v>rray(i, ,) N varE * &i>rray(i, ,)
:e)t ,
:e)t i

>&&licatio".#cree"5&dati"% N 0alse
>ctive4ell.2ffset(RMa), 0).#elect
0or , N 1 To 4Ma)
>ctive4ell.0o"t.!old N True
>ctive4ell.0o"t.-talic N True
>ctive4ell.Galue N PP
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(0, +4Ma)).#elect
>ctive4ell.Galue N P4oeff6P
>ctive4ell.Dori7o"tal>li%"me"t N )lRi%t
>ctive4ell.2ffset(0, 1).#elect
0or , N 2 + 3 To ccMa)
>ctive4ell.Galue N '>rray(,, 1)
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, 1 + 3 + 4Ma)).#elect
0or , N 1 To 4Ma)
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N True
>ctive4ell.Galue N PP
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(0, +4Ma)).#elect
>ctive4ell.Galue N P#t=ev6P
>ctive4ell.Dori7o"tal>li%"me"t N )lRi%t
>ctive4ell.2ffset(0, 1).#elect
0or , N 2 + 3 To ccMa)
-f v>rray(,, ,) R 1(+90 Te"
>ctive4ell.Galue N PR1(+20P
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
(lse
>ctive4ell.Galue N #qr(v>rray(,, ,))
("d -f
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, 1 + 3 + 4Ma)).#elect
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N True
>ctive4ell.Galue N P#f6P
>ctive4ell.Dori7o"tal>li%"me"t N )lRi%t
>ctive4ell.2ffset(0, 1).#elect
>ctive4ell.Galue N #t=ev0
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(1, +1).#elect
' 4om&ute a"d dis&lay te covaria"ce matri)
-f (3 N 0 >"d 4Ma) N B) Te" 8oTo LastLi"e
-f 3 N 0 Te"
0or i N 1 To 4Ma) + 2
0or , N 1 To 4Ma)
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N True
>ctive4ell.0o"t.4olor-"de) N 1
>ctive4ell.Galue N PP
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
:e)t i
>ctive4ell.2ffset(2 + 4Ma), 0).#elect
>ctive4ell.0o"t.!old N True
>ctive4ell.0o"t.4olor-"de) N 11
>ctive4ell.Galue N P4M6P
>ctive4ell.Dori7o"tal>li%"me"t N )lRi%t
>ctive4ell.2ffset(0, 1).#elect
0or i N 1 To 4Ma) + 2
0or , N 1 To 4Ma) + 2
>ctive4ell.0o"t.4olor-"de) N 11
>ctive4ell.Galue N v>rray(i, ,)
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, 2 + 4Ma)).#elect
:e)t i
(lse
0or i N 1 To 4Ma) + 1
0or , N 1 To 4Ma)
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N True
>ctive4ell.0o"t.4olor-"de) N 1
>ctive4ell.Galue N PP
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
:e)t i
>ctive4ell.2ffset(1 + 4Ma), 0).#elect
>ctive4ell.0o"t.!old N True
>ctive4ell.0o"t.4olor-"de) N 11
>ctive4ell.Galue N P4M6P
>ctive4ell.Dori7o"tal>li%"me"t N )lRi%t
>ctive4ell.2ffset(0, 1).#elect
0or i N 1 To 4Ma) + 1
0or , N 1 To 4Ma) + 1
>ctive4ell.0o"t.4olor-"de) N 11
>ctive4ell.Galue N v>rray(i, ,)
>ctive4ell.Dori7o"tal>li%"me"t N )l4e"ter
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, 1 + 4Ma)).#elect
:e)t i
("d -f
>&&licatio".#cree"5&dati"% N True

' 3rovide as o&tio"al out&ut te array of li"ear
' correlatio" coefficie"ts. Te user s&ecifies
' te cell 'loc1 i" wic to write tis array

-f 3 N 0 >"d 4Ma) N B Te" 8oTo LastLi"e
,>"swer N Ms%!o)(P=o you wa"t to see te P Q
? Pmatri) of li"ear correlatio"P Q
? 4r(1B) ? Pcoefficie"tsO -t will "eed a P Q
? P'loc1 of P ? 4Ma) J 3 + 2 Q
? P 'y P ? 4Ma) J 3 + 2 ? P cells.P, v'Ees:o, Q
PLeast #quares 0itP)
' Read locatio" of active cell
>ctive4ell.#elect
my>ddress1 N #electio".>ddress
>ctive4ell.2ffset(4Ma) J 3 + B, 4Ma) J 3 + B).#elect
my>ddress2 N #electio".>ddress
>ctive4ell.2ffset(B + 4Ma) + 3, B + 4Ma) + 3).#elect
!o)>ddress N my>ddress1 ? P6P ? my>ddress2
2utli"eMatri)6

-f ,>"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
P#elect te default array locatio" wit 2L,P Q
? v'4r ? Poterwise ty&e i" your ow" coordi"ates6P, Q
=efault6N!o)>ddress, Ty&e6NK)
myRa"%e.#elect

' Ma1e sure tat te selected 'loc1 as te correct si7e

-f #electio".Rows.4ou"t RI 4Ma) J 3 + 2 Te"
Ms%!o) PTe selected ra"%e does "ot ave P Q
? 4Ma) J 3 + 2 ? P rows. 3lease correct.P, Q
, PLeast #quares 0itP
8oTo 2utli"eMatri)
("d -f
-f #electio".4olum"s.4ou"t RI 4Ma) J 3 + 2 Te"
Ms%!o) PTe selected ra"%e does "ot ave P Q
? 4Ma) J 3 + 2 ? P colum"s. 3lease correctP, Q
, PLeast #quares 0itP
8oTo 2utli"eMatri)
("d -f

' =raw a 'o) arou"d te reserved area

#electio".!orders()l(d%eTo&).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%eTo&).$ei%t N )lTi"
#electio".!orders()l(d%eRi%t).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%eRi%t).$ei%t N )lTi"
#electio".!orders()l(d%e!ottom).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%e!ottom).$ei%t N )lTi"
#electio".!orders()l(d%eLeft).Li"e#tyle N )l=as=ot
#electio".!orders()l(d%eLeft).$ei%t N )lTi"

' 0ormat cells i" array
0or (ac 4ell -" #electio".4ells
4ell.Dori7o"tal>li%"me"t N )l4e"ter
:e)t 4ell
' $rite te array of li"ear correlatio" coefficie"ts
-f 3 N 0 Te"
0or i N 1 To 4Ma) + 2
0or , N 1 To 4Ma) + 2
v0>rray(i, ,) N v>rray(i J 1, , J 1)
:e)t ,
:e)t i
0or i N 1 To 4Ma) + 2
0or , N 1 To 4Ma) + 2
Root N #qr(v0>rray(i, i) * v0>rray(,, ,))
lcc>rray(i, ,) N v0>rray(i, ,) C Root
:e)t ,
:e)t i
#electio".Galue N lcc>rray
("d -f

-f 3 N 1 Te"
0or i N 1 To 4Ma) + 1
0or , N 1 To 4Ma) + 1
v0>rray(i, ,) N v>rray(i, ,)
:e)t ,
:e)t i
0or i N 1 To 4Ma) + 1
0or , N 1 To 4Ma) + 1
Root N #qr(v>rray(i, i) * v>rray(,, ,))
lcc>rray(i, ,) N v>rray(i, ,) C Root
:e)t ,
:e)t i
#electio".Galue N lcc>rray
("d -f
("d -f
LastLi"e6
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''*******************************''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''* "radeByS# *''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''*******************************''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te macro 8rade!y#f com&utes te sta"dard deviatio"s of
' te fit, #f, for all &ossi'le com'i"atio"s a"d &ermuta+
' tio"s of u"wei%ted least squares fits of a de&e"de"t
' varia'le y to a user+s&ecified multivariate e)&ressio"
' of te form y N a1)1 J a2)2 J \ (for PTru 0P, i.e.,
' for a0 N 0) or y N a0 J a1)1 J a2)2 J \ (for te
' P8e"eralP case were te value of a0 is "ot co"strai"ed),
' for u& to si) li"ear terms )i. Te a&&roac used ca"
' 'e e)te"ded readily to more ta" si) varia'les.
' #5!R25T-:(#6
' Te macro 8rade!y#f calls te su'routi"e LL## wic,
' i" tur", calls te su'routi"es -"vert, Multi&ly, a"d
' Tra"s&ose.
' -:35T6
' Te i"&ut data must 'e arra"%ed i" a 'loc1 of at least B
' 42:T-8525# 42L5M:#, wit te de&e"de"t varia'le y i" te
' left+most colum", a"d te i"de&e"de"t varia'les )i to
' its ri%t.
' 25T35T6
' -" order to 1ee& te out&ut com&act, te macro o"ly
' &rovides tree colum"s of out&ut i"formatio"6
' (1) i" its first colum" it lists te i"dices i of te
' &arameters )i co"sidered<
' (2) its seco"d colum" sows te values of te sta"dard
' deviatio" of te fit, #f, assumi"% a0 N 0< a"d
' (B) its tird colum" te values of te sta"dard deviatio"
' of te fit #f for te %e"eral case.
' Dowever, te out&ut will swee& clear a" area as wide as
' te i"&ut array, a"d e)te"di"% 'y rMa) li"es 'elow te
' 'ottom li"e of te out&ut
' $>R:-:86
' Ma1e sure tat tere are "o valua'le data 'elow te
' i"&ut array, 'ecause tese will 'e overwritte". Tis
' macro does :2T cec1 weter tat s&ace is em&ty.
' 3R24(=5R(6
' !efore calli"% te macro, ma1e sure tat te s&ace 'elow
' te i"&ut data array is clear of valua'le data (see a'ove
' u"der $>R:-:8). Te out&ut requires a s&ace as wide as
' te i"&ut array, eve" tou% tat may "ot 'e o'vious from
' te results dis&layed.
' -" order to start te &rocess, i%li%t te i"&ut data
' array, wic sould occu&y at least two ad,ace"t colum"s,
' te" call 8rade!y#f.
' (M>M3L(6
' >(B sectio" B.1H %ives a" e)am&le.
Su& "radeByS#()
=im 4 >s -"te%er, c2 >s -"te%er, cB >s -"te%er
=im c9 >s -"te%er, cH >s -"te%er, cA >s -"te%er
=im cc >s -"te%er, 4Ma) >s -"te%er, ccMa) >s -"te%er
=im =ow" >s -"te%er
=im i >s Lo"%, R >s Lo"%, RMa) >s Lo"%
=im #f >s =ou'le
=im -"&ut>rray >s Garia"t, 2ut&ut>rray >s Garia"t
=im a=, >"swer, M>rray, E>rray
=ow" N 0
' Read i"&ut array data>rray
!e%i"6
-"&ut>rray N #electio".Galue
4Ma) N #electio".4olum"s.4ou"t
RMa) N #electio".Rows.4ou"t
a= N #electio".>ddress
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, P8rade!y#fP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 te si7e of te i"&ut array
-f 4Ma) R B Te"
Ms%!o) PTere sould 'e at least tree i"&ut colum"s.P Q
, , P8rade!y#fP
("d
("d -f
-f 4Ma) I * Te"
Ms%!o) PTis macro ca" o"ly a"dleP ? 4r(1B) ? Q
Psi) i"de&e"de"t &arameters.P, , P8rade!y#fP
("d
("d -f
-f RMa) R 4Ma) J 1 Te"
Ms%!o) PTere are too few rows for te "um+P ? Q
4r(1B) ? P'er of i"de&e"de"t &arameters used.P, Q
, P8rade!y#fP
("d
("d -f
' 4ec1 for missi"% i"&ut data
0or i N 1 To RMa)
-f -s(m&ty(-"&ut>rray(i, 1)) Te"
Ms%!o) PE+value(s) missi"%P, , P8rade!y#fP
("d
("d -f
:e)t i
0or , N 2 To 4Ma)
0or i N 1 To RMa)
-f -s(m&ty(-"&ut>rray(i, ,)) Te"
Ms%!o) PM+value(s) missi"%P, , P8rade!y#fP
("d
("d -f
:e)t i
:e)t ,
' =ime"sio" te data array a"d te out&ut array
Re=im 2ut&ut>rray(1 To RMa), 1 To 4Ma))
Re=im E>rray(1 To RMa), 1 To 1) >s =ou'le
Re=im M>rray(1 To RMa), 1 To 1) >s =ou'le
' 0ill y>rray
0or R N 1 To RMa)
E>rray(R, 1) N -"&ut>rray(R, 1)
:e)t R
' -"itiali7e )>rray
0or R N 1 To RMa)
0or 4 N 1 To 4Ma)
2ut&ut>rray(R, 4) N PP
:e)t 4
:e)t R
#electio".2ffset(RMa) J 1, 0).#elect
=ow" N =ow" J RMa) J 1
' $rite colum" eadi"%s
2ut&ut>rray(1, 1) N P#ta"dard deviatio" of fitP
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
2ut&ut>rray(1, 1) N P-"dices6P
2ut&ut>rray(1, 2) N PTru 0P
2ut&ut>rray(1, B) N P8e"eralP
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 1).#elect
$it >ctive4ell
.Galue N P8rade!y#fP
.0o"t.!old N True
.0o"t.4olor-"de) N H
.0o"t.-talic N 0alse
.Dori7o"tal>li%"me"t N )l4e"ter
.-"terior.4olor-"de) N 20
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
P8rade!y#f versio" *P ? 4r(10) ? Q
P-"&ut6 P ? a= ? 4r(10) ? 4r(10) ? Q
Pdate6 P ? =ate ? 4r(10) ? Ptime6 P ? Time
("d $it
#electio".2ffset(1, +1).#elect
=ow" N =ow" J B
' 4om&ute te out&ut for 1 varia'le6
ccMa) N 9
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #f)
2ut&ut>rray(1, 1) N 4 + 1
2ut&ut>rray(1, 2) N #f
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #f)
2ut&ut>rray(1, B) N #f
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for 2 varia'les6
ccMa) N H
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #f)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1
2ut&ut>rray(1, 2) N #f
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #f)
2ut&ut>rray(1, B) N #f
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for B varia'les6
ccMa) N A
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
M>rray(R, 9) N -"&ut>rray(R, cB)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #f)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1 ? P,P ? cB + 1
2ut&ut>rray(1, 2) N #f
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #f)
2ut&ut>rray(1, B) N #f
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for 9 varia'les6
ccMa) N *
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or c9 N cB J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
M>rray(R, 9) N -"&ut>rray(R, cB)
M>rray(R, H) N -"&ut>rray(R, c9)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #f)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1 ? Q
P,P ? cB + 1 ? P,P ? c9 + 1
2ut&ut>rray(1, 2) N #f
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #f)
2ut&ut>rray(1, B) N #f
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t c9
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for H varia'les6
ccMa) N K
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or c9 N cB J 1 To 4Ma)
0or cH N c9 J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
M>rray(R, 9) N -"&ut>rray(R, cB)
M>rray(R, H) N -"&ut>rray(R, c9)
M>rray(R, A) N -"&ut>rray(R, cH)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #f)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1 ? Q
P,P ? cB + 1 ? P,P ? c9 + 1 ? P,P ? cH + 1
2ut&ut>rray(1, 2) N #f
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #f)
2ut&ut>rray(1, B) N #f
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t cH
:e)t c9
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for A varia'les6
ccMa) N @
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or c9 N cB J 1 To 4Ma)
0or cH N c9 J 1 To 4Ma)
0or cA N cH J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 4) N -"&ut>rray(R, 2)
M>rray(R, c2) N -"&ut>rray(R, B)
M>rray(R, cB) N -"&ut>rray(R, 9)
M>rray(R, c9) N -"&ut>rray(R, H)
M>rray(R, cH) N -"&ut>rray(R, A)
M>rray(R, cA) N -"&ut>rray(R, *)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #f)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? Q
P,P ? c2 + 1 ? P,P ? cB + 1 ? P,P ? Q
c9 + 1 ? cH + 1 ? P,P ? cA + 1
2ut&ut>rray(1, 2) N #f
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #f)
2ut&ut>rray(1, B) N #f
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t cA
:e)t cH
:e)t c9
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(+=ow", 0).#elect
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''*****************************''''''''''''''
''''''''''''''''* *''''''''''''''
''''''''''''''''* Least suares poly *''''''''''''''
''''''''''''''''* *''''''''''''''
''''''''''''''''*****************************''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te macros L#3oly0 a"d L#3oly1 com&ute te &arameters a"d
' teir sta"dard deviatio"s for a" u"wei%ted least squares
' fit of a de&e"de"t varia'le y to a &ower series i" ) of
' i"creasi"% (&ositive i"te%er) order m, u& to 19. Te user
' s&ecifies te i%est order to 'e dis&layed.
'
' 5se te custom macros 2rto1 or 2rto0 i" order to decide
' wat &oly"omial order mi%t 'e o&timal.
' #5!R25T-:(#6
' Te macros L#3olyO a"d L#3olyI call te su'routi"e
' Least#quares3oly wic, i" tur", calls te su'routi"es
' -"vert, Multi&ly, a"d Tra"s&ose.
' -:35T6
' Te i"&ut data must 'e arra"%ed i" a 'loc1 of two ad,a+
' ce"t colum"s, wit te de&e"de"t varia'le y i" te left+
' most colum", a"d te i"de&e"de"t varia'le ) to its ri%t.
' Di%li%t te data i" tese two colum"s, a"d call te
' macro L#3olyO or L#3olyI. Te" s&ecify te ma)imum &oly+
' "omial order for wic you wa"t te results dis&layed.
' 25T35T6
' Te macro &rovides6
' (1) te coefficie"ts of te least squares fit of y to te
' &ower series a(1)) J a(2));2 J ... N #umXa(i));iY for
' i N 1(1)m for L#3olyO, or to a(0) J a(1)) J a(2));2
' J ... N #umXa(i));iY for i N 0(1)m for L#3oly1<
' (2) te corres&o"di"% sta"dard deviatio"s s
' for tese coefficie"ts<
' (B) te sta"dard deviatio" of te fit
' for eac value of m<
' (9) te 0+ratios for al&a N 0.0H a"d 0.01
' for eac value of m.
'
' 0or eac order te out&ut co"sists of tree rows. Te to&
' row lists te order of te &oly"omial, a"d te sta"dard
' deviatio" of te fit. Te seco"d row dis&lays te coeffi+
' cie"ts of te fitted &oly"omial, a"d te tird row te
' corres&o"di"% sta"dard deviatio"s. Te seco"d a"d tird
' rows also list te values for te 0+ratios for H[ a"d 1[
' res&ectively. 0or easy readi"% te rows are color+coded
' 'y order.
' -f you wa"t te out&ut to dis&lay more di%its, ca"%e
' te i"structio" >ctive4ell.:um'er0ormat N P0.00(J00P to
' >ctive4ell.:um'er0ormat N P0.000(J00P, P0.0000(J00P, etc.
' $>R:-:8#6
' Te out&ut is dis&layed 'elow te i%li%ted i"&ut
' array, a"d terefore mi%t esca&e your "otice. -f
' te macro does"'t seem to res&o"d, loo1 'elow it.
'
' -f you fi"d cells filled wit ]]]]]] te macro "eeds
' wider colum"s to dis&lay its results. 4lic1 o" te
' colum" "ame(s) at te to& of te colum"(s), ri%t+clic1,
' a"d i"sert a lar%er "um'er i" 4olum" $idt.
' Te si7e of te macro out&ut will 'e determi"ed 'y your
' coice of te ma)imum &oly"omial order. Te out&ut will
' 'e dis&layed u"der te i"&ut data, a"d will %radually
' e)&a"d to te ri%t as results for i%er orders occu&y
' i"creasi"%ly more s&ace. Te first+order out&ut will
' occu&y a 'loc1 of B rows of H colum"s for L#3oly0 (A
' for L#3oly1), a"d eac additio"al order will use a
' 'loc1 tat is o"e colum" wider ta" its &redecessor.
' 3lease move valua'le data from te out&ut re%io" 'efore
' ru""i"% tis macro, lest tose data 'e overwritte".
' 3R24(=5R(6
' !efore calli"% te macro, ma1e sure tat te out&ut area
' is clear of valua'le data (see a'ove u"der $>R:-:8)
'
' -" order to start te &rocess, i%li%t te (two colum"s
' wide, a"d at least B rows i%) i"&ut data 'loc1, te"
' call L#3oly0 or L#3oly1.
' (M>M3L(6
' 5se of tis macro is illustrated i" sectio"s B.10, B.1B
' a"d B.19 of >(B.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Te fu"ctio" of te followi"% two drivers is merely to
' set te value of o"e &arameter, &, equal to eiter o"e or
' 7ero, i" order to coose 'etwee" a %e"eral least squares
' fitti"% (& N 1) or o"e tat forces te curve trou% te
' ori%i" (& N 0).
Su& LSPolyO() ' for u"wei%ted least squares
' fit trou% te ori%i"
=im 3 >s =ou'le
3 N 0
4all Least#quares3oly(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& LSPolyI() ' for %e"eral u"wei%ted
' least squares fit
=im 3 >s =ou'le
3 N 1
4all Least#quares3oly(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& LeastSuaresPoly(3)
=im 4Ma) >s -"te%er, 4olor(1 To *) >s -"te%er
=im , >s -"te%er, m >s -"te%er, : >s -"te%er
=im Ma)2rder >s -"te%er, Ma)2rderMa) >s -"te%er
=im i >s Lo"%, RMa) >s Lo"%
=im 0Ratio1 >s =ou'le, 0RatioH >s =ou'le
=im Root >s =ou'le, #t=ev0 >s =ou'le
=im u >s =ou'le, Z >s =ou'le
=im =ata>rray >s Garia"t, 0 >s Garia"t, lcc>rray >s Garia"t
=im 2ut&ut>rray >s Garia"t, ##R >s Garia"t
=im varE >s Garia"t, v>rray >s Garia"t, v0>rray >s Garia"t
=im myRa"%e >s Ra"%e
=im '>rray, 't>rray, 'tq>rray, &>rray, &i>rray
=im q>rray, M>rray, )t>rray, E>rray, yt>rray, yty>rray
=im >"swer, i>"swer, >"swer, 1>"swer
' =etermi"atio" of te array si7e6
!e%i"6
RMa) N #electio".Rows.4ou"t
4Ma) N #electio".4olum"s.4ou"t
Re=im 0(1 To RMa), 1 To 1) >s =ou'le
Re=im ##R(1 To RMa), 1 To 1) >s =ou'le
u N 1
Z N 0
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, PL#3olyP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 tat te "um'er of colum"s is 26
-f 4Ma) RI 2 Te"
Ms%!o) PTere must 'e two colum"s,P ? Q
4r(1B) ? Po"e for E, a"d o"e for M.P, Q
, PLeast #quares 3oly"omial 0itP
("d
("d -f
' 4ec1 tat rma) I B, so tat te "um'er of data
' &oi"ts is sufficie"t to defi"e te &ro'lem6
-f RMa) R 9 Te"
Ms%!o) PTere must 'e at least 9 i"&utP ? Q
4r(1B) ? Pdata &airs to defi"e te &ro'lem.P, Q
, PLeast #quares 3oly"omial 0itP
("d
("d -f

Ma)2rderMa) N 19
-f RMa) R 1A Te" Ma)2rderMa) N RMa) + 2
=ata>rray N #electio".Galue
#electio".-tem(1, 1).#elect
' #elect te ma)imum order6
Ma)2rder N -"&ut!o) Q
(P#elect as ma)imum order a" i"te%erP ? 4r(1B) ? Q
P'etwee" B a"d P ? Ma)2rderMa) ? P.P ? 4r(1B) ? Q
4r(1B) ? P("ter te ma)imum order6 P, PMa)2rderP)
-f Ma)2rder R B Te" Ma)2rder N B
-f Ma)2rder I Ma)2rderMa) Te" Ma)2rder N Ma)2rderMa)
Redime"sio">rrays6

' =ime"sio" te arrays6
Re=im E>rray(1 To RMa), 1 To 1) >s =ou'le
Re=im M>rray(1 To RMa), 1 To 4Ma)) >s =ou'le
Re=im yt>rray(1 To 1, 1 To RMa)) >s =ou'le
Re=im yty>rray(1 To 1, 1 To 1) >s =ou'le
Re=im )t>rray(1 To 4Ma), 1 To RMa)) >s =ou'le
Re=im &>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im &i>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im q>rray(1 To 4Ma), 1 To 1) >s =ou'le
Re=im '>rray(1 To 4Ma), 1 To 1) >s =ou'le
Re=im 't>rray(1 To 1, 1 To 4Ma)) >s =ou'le
Re=im 'tq>rray(1 To 1, 1 To 1) >s =ou'le
Re=im v>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im v0>rray(1 To 4Ma) + 1 J 3, 1 To 4Ma) + 1 J 3) Q
>s =ou'le
Re=im lcc>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
' Read te data>rray, te" fill y>rray a"d )>rray.
0or i N 1 To RMa)
E>rray(i, 1) N =ata>rray(i, 1)
:e)t i
-f 4Ma) N 2 Te"
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, 1)) Te"
Ms%!o) PE+value(s) missi"%P, Q
, PLeast #quares 3oly"omial 0itP
("d
("d -f
:e)t i
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, 2)) Te"
Ms%!o) PM+value(s) missi"%P, Q
, PLeast #quares 3oly"omial 0itP
("d
("d -f
:e)t i
("d -f
' 0ill te first colum" of )>rray wit 7eroes
' (for & N 0) or o"es (for & N 1), te rest
' wit te data i" te )+colum"(s)
0or i N 1 To RMa)
M>rray(i, 1) N 4='l(3)
:e)t i
0or i N 1 To RMa)
M>rray(i, 2) N =ata>rray(i, 2)
:e)t i
-f 4Ma) I 2 Te"
0or , N B To 4Ma)
0or i N 1 To RMa)
M>rray(i, ,) N M>rray(i, 2) * M>rray(i, , + 1)
:e)t i
:e)t ,
("d -f
' 4om&ute ' N (M' M)P M' E , were ' or t de"ote
' tra"s&ositio", a"d P or i i"dicate i"versio"
' Te various arrays a"d teir dime"sio"s (rows,
' colum"s) are6
' E N y>rray ( rma), 1)
' M N )>rray ( rma), cma))
' M' N )t>rray ( cma), rma))
' M' M N &>rray ( cma), cma))
' (M' M)P N &i>rray ( cma), cma))
' M' E N q>rray ( cma), 1)
' ' N '>rray ( cma), 1)
' E' N yt>rray ( 1, rma))
' E' E N yty>rray ( 1, 1)
' '' N 't>rray ( 1, cma))
' '' M' E N 'tq>rray ( 1, 1)
4all Tra"s&ose(M>rray, RMa), 4Ma), )t>rray)
4all Multi&ly()t>rray, 4Ma), RMa), M>rray, 4Ma), &>rray)
4all -"vert(&>rray, 4Ma), &i>rray)
4all Multi&ly()t>rray, 4Ma), RMa), E>rray, 1, q>rray)
4all Multi&ly(&i>rray, 4Ma), 4Ma), q>rray, 1, '>rray)
4all Tra"s&ose(E>rray, RMa), 1, yt>rray)
4all Tra"s&ose('>rray, 4Ma), 1, 't>rray)
4all Multi&ly(yt>rray, 1, RMa), E>rray, 1, yty>rray)
4all Multi&ly('t>rray, 1, 4Ma), q>rray, 1, 'tq>rray)
' 4alculate ##R N E'E + ''M'E, a"d te" varE, te varia"ce
' of y, as varE N ##RC(rma)+cma)+&J1)< a"d v>rray, te co+
' varia"ce matri), as G N (M'M)P times varE, of wic we
' ere o"ly use te dia%o"al eleme"ts, i.e., te varia"ces.
##R(4Ma), 1) N yty>rray(1, 1) + 'tq>rray(1, 1)
varE N ##R(4Ma), 1) C (RMa) + 4Ma) J 1 + 3)
#t=ev0 N #qr(>'s(varE))
-f 4Ma) I 2 Te"
0(4Ma), 1) N ((##R(4Ma) + 1, 1) C ##R(4Ma), 1)) + 1) Q
* (RMa) + 4Ma) J 1 + 3)
0RatioH N (0(4Ma), 1)) C Q
(>&&licatio".0-"v(0.0H, 1, RMa) + 4Ma) J 1 + 3))
0Ratio1 N (0(4Ma), 1)) C Q
(>&&licatio".0-"v(0.01, 1, RMa) + 4Ma) J 1 + 3))
("d -f
0or i N 1 To 4Ma)
0or , N 1 To 4Ma)
v>rray(i, ,) N varE * &i>rray(i, ,)
:e)t ,
:e)t i
>&&licatio".#cree"5&dati"% N 0alse
>ctive4ell.2ffset(RMa) J 1, 0).#elect
' 3ai"t color 'a"ds for u& to 19 orders, a"d set te
' "umerical format to scie"tific wit B decimal &laces
4olor(1) N BK
4olor(2) N 90
4olor(B) N BA
4olor(9) N BH
4olor(H) N B9
4olor(A) N B*
4olor(*) N B@
0or i N 1 To B
0or , N 1 To 4Ma) J 3 J 2
>ctive4ell.4lear4o"te"ts
-f 4Ma) R @ Te"
>ctive4ell.-"terior.4olor-"de) N 4olor(4Ma) + 1)
(lse
>ctive4ell.-"terior.4olor-"de) N 4olor(4Ma) + K)
("d -f
>ctive4ell.2ffset(0, 1).#elect
-f 4Ma) R @ Te"
>ctive4ell.-"terior.4olor-"de) N 4olor(4Ma) + 1)
(lse
>ctive4ell.-"terior.4olor-"de) N 4olor(4Ma) + K)
("d -f
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N 0alse
>ctive4ell.:um'er0ormat N P0.00(J00P
:e)t ,
>ctive4ell.2ffset(1, +4Ma) + 3 + 2).#elect
:e)t i
>ctive4ell.2ffset(+B, 0).#elect
' =is&lay te to& li"e of te out&ut
$it >ctive4ell
.0o"t.!old N True
.0o"t.-talic N 0alse
.Dori7o"tal>li%"me"t N )lLeft
.Galue N P2rder P ? 4Ma) + 1
("d $it
0or , N 1 To 4Ma) J 3 + 1
#electio".2ffset(0, 1).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )l4e"ter
.Galue N Pterm P ? , + 3
("d $it
:e)t ,
#electio".2ffset(0, 2).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P#f6P
("d $it
#electio".2ffset(0, 1).#elect
#electio".Dori7o"tal>li%"me"t N )lLeft
#electio".Galue N #t=ev0
#electio".2ffset(1, +4Ma) + 3 + 2).#elect
' =is&lay te ce"ter li"e of te out&ut
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P4oeff6P
("d $it
0or , N 1 To 4Ma) J 3 + 1
#electio".2ffset(0, 1).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N 0alse
.Dori7o"tal>li%"me"t N )l4e"ter
.Galue N '>rray(, J 1 + 3, 1)
("d $it
:e)t ,
#electio".2ffset(0, 2).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P0RH6P
("d $it
#electio".2ffset(0, 1).#elect
#electio".Dori7o"tal>li%"me"t N )lLeft
-f 4Ma) N 2 Te" #electio".Galue N P:C>P
-f 4Ma) I 2 Te" #electio".Galue N 0RatioH
#electio".2ffset(1, +4Ma) + 3 + 2).#elect
' =is&lay te 'ottom li"e of te out&ut
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P#t=ev6P
("d $it
0or , N 1 To 4Ma) J 3 + 1
#electio".2ffset(0, 1).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N 0alse
.Dori7o"tal>li%"me"t N )l4e"ter
("d $it
-f v>rray(, + 3 J 1, , + 3 J 1) R 1(+90 Te"
>ctive4ell.Galue N PR1(+20P
(lse
>ctive4ell.Galue N Q
#qr(>'s(v>rray(, + 3 J 1, , + 3 J 1)))
("d -f
:e)t ,
#electio".2ffset(0, 2).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P0R16P
("d $it
#electio".2ffset(0, 1).#elect
#electio".Dori7o"tal>li%"me"t N )lLeft
-f 4Ma) N 2 Te" #electio".Galue N P:C>P
-f 4Ma) I 2 Te" #electio".Galue N 0Ratio1
#electio".2ffset(1, +4Ma) + 3 + 2).#elect
-f 4Ma) R Ma)2rder J 2 Te" 4Ma) N 4Ma) J 1
>ctive4ell.2ffset(+RMa) + 1, 0).#elect
-f 4Ma) N Ma)2rder J 2 Te" ("d
8oTo Redime"sio">rrays
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''****************************'''''''''''''''
''''''''''''''''* *'''''''''''''''
''''''''''''''''* Least suares multi *''''''''''''''
''''''''''''''''* *'''''''''''''''
''''''''''''''''****************************'''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te macros L#MultiO a"d L#MultiI com&ute te &arameters
' a"d teir sta"dard deviatio"s for a" u"wei%ted least
' squares fit of a de&e"de"t varia'le y to a user+s&ecified
' multivariate e)&ressio" of te form y N a1)1 J a2)2 J ..
' (for L#Multi2) or y N a0 J a1)1 J a2)2 J ...(for
' L#Multi-) 'y %radually (o"e term at a time) i"creasi"%
' te "um'er of terms i"cluded i" te least squares
' a"alysis from left to ri%t
' :ote tat te macro does :2T rearra"%e te colum"s, a"d
' terefore does "ot &rovide all &ossi'le &ermutatio"s.
' -f tose &ossi'le &ermutatio"s are "eeded, i"stead use
' te macros L#3ermute0 or L#3ermute1.
' Te macro yields6 te fitti"% coefficie"ts a(i), teir
' sta"dard deviatio"s s(i), te sta"dard deviatio" of te
' over+all fit, s(y), a"d te results of two 0+tests, 0RH
' a"d 0R1, for H[ a"d 1[ &ro'a'ility res&ectively.
' #5!R25T-:(#6
' Te macros L#Multi0 a"d L#Multi1 call te su'routi"e
' L#Multi wic, i" tur", calls te su'routi"es -"vert,
' Multi&ly, a"d Tra"s&ose.
' -:35T6
' Te i"&ut data must 'e arra"%ed i" a 'loc1 of at least B
' (for L#Multi0) or 9 (for L#Multi1) ad,ace"t colum"s, wit
' te de&e"de"t varia'le y i" te left+most colum", a"d te
' i"de&e"de"t varia'les ) to its ri%t. Di%li%t te data
' i" tese colum"s, a"d call te macro L#Multi0 or L#Multi1
' 25T35T6
' Te macro &rovides6
' (1) te coefficie"ts of te least squares fit of y to
' te series a(1))(1) J a(2));2 J ... J a(i));i
' N #umXa(i))(i)Y for i N 1(1)m for L#Multi0, or
' a(0) J a(1))(1) J a(1))(2) J ... N #umXa(i))(i)Y
' for i N 0(1)m for L#Multi1<
' (2) te corres&o"di"% sta"dard deviatio"s s for tese
' coefficie"ts<
' (B) te corres&o"di"% sta"dard deviatio" of te fit< a"d
' (9) te corres&o"di"% 0+ratios for al&a N 0.0H a"d 0.01.
'
' 0or eac order te out&ut co"sists of tree rows. Te to&
' row lists te sta"dard deviatio" of te fit. Te seco"d
' row dis&lays te coefficie"ts of te fitted &oly"omial,
' a"d te tird row te corres&o"di"% sta"dard deviatio"s.
' Te seco"d a"d tird rows also list te values for te
' 0+ratios for H[ a"d 1[ res&ectively. 0or easy readi"%
' te rows are color+coded.
' -f you wa"t te out&ut to dis&lay more di%its, ca"%e
' te i"structio" >ctive4ell.:um'er0ormat N P0.00(J00P to
' >ctive4ell.:um'er0ormat N P0.000(J00P, P0.0000(J00P, etc.
' $>R:-:86
' Te macro out&ut will ta1e u& muc s&ace 'elow a"d to te
' ri%t of te i"&ut data. 3lease move valua'le data from
' te out&ut re%io" 'efore ru""i"% tis macro, lest tose
' data 'e overwritte".
'
' 3R24(=5R(6
'
' !efore calli"% te macro, ma1e sure tat te out&ut area
' is clear of valua'le data (see a'ove u"der $>R:-:8). Te
' macro does :2T cec1 weter tat area is free of data.
' -" order to start te &rocess, i%li%t te i"&ut data,
' wic sould occu&y at least tree ad,ace"t colum"s, te"
' call L#Multi0 or L#Multi1.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Te fu"ctio" of te followi"% two drivers is merely to
' set te value of o"e &arameter, &, equal to eiter o"e or
' 7ero, i" order to coose 'etwee" a %e"eral least squares
' fitti"% (& N 1) or o"e tat forces te curve trou% te
' ori%i" (& N 0).
Su& LSMultiO() ' for u"wei%ted least squares
' fit trou% te ori%i"
=im 3 >s =ou'le
3 N 0
4all L#Multi(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& LSMultiI() ' for %e"eral u"wei%ted
' least squares fit
=im 3 >s =ou'le
3 N 1
4all L#Multi(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& LSMulti(3)
=im 4Ma) >s -"te%er, 4olor(1 To *) >s -"te%er
=im , >s -"te%er, m >s -"te%er, MM >s -"te%er
=im Ma)2rder >s -"te%er, : >s -"te%er
=im i >s Lo"%, RMa) >s Lo"%
=im 0Ratio1 >s =ou'le, 0RatioH >s =ou'le
=im Root >s =ou'le, #t=ev0 >s =ou'le
=im u >s =ou'le, Z >s =ou'le
=im =ata>rray >s Garia"t, 0 >s Garia"t
=im lcc>rray >s Garia"t, 2ut&ut>rray >s Garia"t
=im ##R >s Garia"t, varE >s Garia"t
=im v>rray >s Garia"t, v0>rray >s Garia"t
=im myRa"%e >s Ra"%e
=im '>rray, 't>rray, 'tq>rray, M1, M2, &>rray, &i>rray
=im q>rray, M>rray, )t>rray, E>rray, yt>rray, yty>rray
=im >"swer, i>"swer, >"swer, 1>"swer
' =etermi"atio" of te array si7e6
!e%i"6
RMa) N #electio".Rows.4ou"t
4Ma) N #electio".4olum"s.4ou"t
Re=im 0(1 To RMa), 1 To 1) >s =ou'le
Re=im ##R(1 To RMa), 1 To 1) >s =ou'le
u N 1
Z N 0
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, PL#MultiP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 tat te "um'er of colum"s is at least (BJ&)6
-f 4Ma) R B J 3 Te"
Ms%!o) PTere must 'e at least P ? B J 3 ? P colum"s.P, Q
, PLeast #quares Multivariate 0itP
("d
("d -f
' 4ec1 tat rma) I cma)J1, so tat te "um'er of data
' &oi"ts is sufficie"t to defi"e te &ro'lem6
-f RMa) R 4Ma) J 1 Te"
Ms%!o) P Tere must 'e at least P ? 4Ma) J 1 ? Q
4r(1B) ? Pi"&ut data &airs to defi"e te &ro'lem.P, Q
, PLeast #quares Multivariate 0itP
("d
("d -f

=ata>rray N #electio".Galue
#electio".-tem(1, 1).#elect
MM N 2
Redime"sio">rrays6

' =ime"sio" te arrays6
Re=im E>rray(1 To RMa), 1 To 1) >s =ou'le
Re=im M>rray(1 To RMa), 1 To MM) >s =ou'le
Re=im yt>rray(1 To 1, 1 To RMa)) >s =ou'le
Re=im yty>rray(1 To 1, 1 To 1) >s =ou'le
Re=im )t>rray(1 To MM, 1 To RMa)) >s =ou'le
Re=im &>rray(1 To MM, 1 To MM) >s =ou'le
Re=im &i>rray(1 To MM, 1 To 4Ma)) >s =ou'le
Re=im q>rray(1 To MM, 1 To 1) >s =ou'le
Re=im '>rray(1 To MM, 1 To 1) >s =ou'le
Re=im 't>rray(1 To 1, 1 To MM) >s =ou'le
Re=im 'tq>rray(1 To 1, 1 To 1) >s =ou'le
Re=im v>rray(1 To MM, 1 To MM) >s =ou'le
Re=im v0>rray(1 To MM + 1 J 3, 1 To MM + 1 J 3) >s =ou'le
Re=im lcc>rray(1 To MM, 1 To MM) >s =ou'le
' Read te data>rray, te" fill y>rray a"d )>rray.
0or i N 1 To RMa)
E>rray(i, 1) N =ata>rray(i, 1)
:e)t i
' 4ec1 te i"&ut data for co"ti%uity.
-f MM N 2 Te"
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, 1)) Te"
Ms%!o) PE+value(s) missi"%P, Q
, PLeast #quares Multivariate 0itP
("d
("d -f
:e)t i
0or i N 1 To RMa)
0or , N 2 To 4Ma)
-f -s(m&ty(=ata>rray(i, ,)) Te"
Ms%!o) PM+value(s) missi"%P, Q
, PLeast #quares Multivariate 0itP
("d
("d -f
:e)t ,
:e)t i
("d -f
' 0ill te first colum" of )>rray wit eiter
' 7eros (for & N 0) or o"es (for & N 1),
' te rest wit te data i" te )+colum"(s)
0or i N 1 To RMa)
M>rray(i, 1) N 4='l(3)
:e)t i
0or i N 1 To RMa)
M>rray(i, 2) N =ata>rray(i, 2)
:e)t i
-f MM I 2 Te"
0or i N 1 To RMa)
0or , N B To MM
M>rray(i, ,) N =ata>rray(i, ,)
:e)t ,
:e)t i
("d -f
' 4om&ute ' N (M' M)P M' E , were ' or t de"ote
' tra"s&ositio", a"d P or i i"dicate i"versio"
' Te various arrays a"d teir dime"sio"s (rows,
' colum"s) are6
' E N y>rray ( rma), 1)
' M N )>rray ( rma), mm)
' M' N )t>rray ( mm, rma))
' M' M N &>rray ( mm, mm)
' (M' M)P N &i>rray ( mm, mm)
' M' E N q>rray ( mm, 1)
' ' N '>rray ( mm, 1)
' E' N yt>rray ( 1, rma))
' E' E N yty>rray ( 1, 1)
' '' N 't>rray ( 1, mm)
' '' M' E N 'tq>rray ( 1, 1)
4all Tra"s&ose(M>rray, RMa), MM, )t>rray)
4all Multi&ly()t>rray, MM, RMa), M>rray, MM, &>rray)
4all -"vert(&>rray, MM, &i>rray)
4all Multi&ly()t>rray, MM, RMa), E>rray, 1, q>rray)
4all Multi&ly(&i>rray, MM, MM, q>rray, 1, '>rray)
4all Tra"s&ose(E>rray, RMa), 1, yt>rray)
4all Tra"s&ose('>rray, MM, 1, 't>rray)
4all Multi&ly(yt>rray, 1, RMa), E>rray, 1, yty>rray)
4all Multi&ly('t>rray, 1, MM, q>rray, 1, 'tq>rray)
' 4alculate ##R N E'E + ''M'E, a"d te" varE, te varia"ce
' of y, as varE N ##RC(rma)+cma)+&J1)< a"d v>rray, te
' covaria"ce matri), as G N (M'M)P times varE, of wic we
' ere o"ly use te dia%o"al eleme"ts, i.e., te varia"ces

0or i N 1 To MM
0or , N 1 To MM
v>rray(i, ,) N varE * &i>rray(i, ,)
:e)t ,
:e)t i
>&&licatio".#cree"5&dati"% N 0alse
>ctive4ell.2ffset(RMa) J 1, 0).#elect
' 3ai"t color 'a"ds for u& to 19 orders, a"d set te
' "umerical format to scie"tific wit B decimal &laces
4olor(1) N BK
4olor(2) N 90
4olor(B) N BA
4olor(9) N BH
4olor(H) N B9
4olor(A) N B*
4olor(*) N B@
0or i N 1 To B
0or , N 1 To MM J 3 J 2
>ctive4ell.4lear4o"te"ts
-f MM R @ Te"
>ctive4ell.-"terior.4olor-"de) N 4olor(MM + 1)
(lse
>ctive4ell.-"terior.4olor-"de) N 4olor(MM + K)
("d -f
>ctive4ell.2ffset(0, 1).#elect
-f MM R @ Te"
>ctive4ell.-"terior.4olor-"de) N 4olor(MM + 1)
(lse
>ctive4ell.-"terior.4olor-"de) N 4olor(MM + K)
("d -f
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N 0alse
>ctive4ell.:um'er0ormat N P0.00(J00P
:e)t ,
>ctive4ell.2ffset(1, +MM + 3 + 2).#elect
:e)t i
>ctive4ell.2ffset(+B, 0).#elect
' =is&lay te to& li"e of te out&ut
$it >ctive4ell
.0o"t.!old N True
.0o"t.-talic N 0alse
.Dori7o"tal>li%"me"t N )lLeft
.Galue N P#et ] P ? MM + 1
("d $it
0or , N 1 To MM J 3 + 1
#electio".2ffset(0, 1).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )l4e"ter
.Galue N Pterm P ? , + 3
("d $it
:e)t ,
#electio".2ffset(0, 2).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P#f6P
("d $it
#electio".2ffset(0, 1).#elect
#electio".Dori7o"tal>li%"me"t N )lLeft
#electio".Galue N #t=ev0
#electio".2ffset(1, +MM + 3 + 2).#elect
' =is&lay te ce"ter li"e of te out&ut
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P4oeff6P
("d $it
0or , N 1 To MM J 3 + 1
#electio".2ffset(0, 1).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N 0alse
.Dori7o"tal>li%"me"t N )l4e"ter
.Galue N '>rray(, J 1 + 3, 1)
("d $it
:e)t ,
#electio".2ffset(0, 2).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P0RH6P
("d $it
#electio".2ffset(0, 1).#elect
#electio".Dori7o"tal>li%"me"t N )lLeft
-f MM N 2 Te" #electio".Galue N P:C>P
-f MM I 2 Te" #electio".Galue N 0RatioH
#electio".2ffset(1, +MM + 3 + 2).#elect
' =is&lay te 'ottom li"e of te out&ut
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P#t=ev6P
("d $it
0or , N 1 To MM J 3 + 1
#electio".2ffset(0, 1).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N 0alse
.Dori7o"tal>li%"me"t N )l4e"ter
("d $it
-f v>rray(, + 3 J 1, , + 3 J 1) R 1(+90 Te"
>ctive4ell.Galue N PR1(+20P
(lse
>ctive4ell.Galue N Q
#qr(>'s(v>rray(, + 3 J 1, , + 3 J 1)))
("d -f
:e)t ,
#electio".2ffset(0, 2).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P0R16P
("d $it
#electio".2ffset(0, 1).#elect
#electio".Dori7o"tal>li%"me"t N )lLeft
-f MM N 2 Te" #electio".Galue N P:C>P
-f MM I 2 Te" #electio".Galue N 0Ratio1
#electio".2ffset(1, +MM + 3 + 2).#elect
-f MM R 4Ma) J 1 Te" MM N MM J 1
>ctive4ell.2ffset(+RMa) + 1, 0).#elect
-f MM N 4Ma) J 1 Te" ("d
8oTo Redime"sio">rrays
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''*******************************''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''* Least suares permute *''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''*******************************''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te macro L#3ermute com&utes te sta"dard deviatio"s of
' te fit, sf, for all &ossi'le com'i"atio"s a"d &ermuta+
' tio"s of u"wei%ted least squares fits of a de&e"de"t
' varia'le y to a user+s&ecified multivariate e)&ressio" of
' te form y N a1)1 J a2)2 J .. (for PTru 0P, i.e., for a0
' N 0) or y N a0 J a1)1 J a2)2 J .. (for te P8e"eralP case
' were te value of a0 is "ot co"strai"ed), for u& to si)
' li"ear terms )i.
' #5!R25T-:(#6
' Te macro L#3ermute calls te su'routi"e LL## wic,
' i" tur", calls te su'routi"es -"vert, Multi&ly, a"d
' Tra"s&ose.
' -:35T6
' Te i"&ut data must 'e arra"%ed i" a 'loc1 of at least B
' co"ti%uous colum"s, wit te de&e"de"t varia'le y i" te
' left+most colum", a"d te i"de&e"de"t varia'les )i to
' its ri%t.
' 25T35T6
' -" order to 1ee& te out&ut com&act, te macro o"ly
' &rovides tree colum"s of out&ut i"formatio"6
' (1) i" its first colum" te i"dices i of te &arameters
' )i co"sidered<
' (2) i" its seco"d colum" te values of te sta"dard
' deviatio" of te fit, #f, assumi"% a0 N 0< a"d
' (B) i" its tird colum" te values of te sta"dard
' deviatio" of te fit #f for te %e"eral case.
' Dowever, te out&ut will swee& clear a" area as wide as
' te i"&ut array, a"d e)te"di"% 'y rMa) li"es 'elow te
' 'ottom li"e of te out&ut
' $>R:-:86
' Ma1e sure tat tere are "o valua'le data 'elow te
' i"&ut array, 'ecause tese will 'e overwritte". Tis
' macro does :2T cec1 weter tat s&ace is em&ty.
' 3R24(=5R(6
' !efore calli"% te macro, ma1e sure tat te s&ace 'elow
' te i"&ut data array is clear of valua'le data (see a'ove
' u"der $>R:-:8). Te out&ut requires a s&ace as wide as
' te i"&ut array, eve" tou% tat may "ot 'e o'vious from
' te results dis&layed.
' -" order to start te &rocess, i%li%t te i"&ut data
' array, wic sould occu&y at least two ad,ace"t colum"s,
' te" call L#3ermute.
Su& LSPermute()
=im 4 >s -"te%er, c2 >s -"te%er, cB >s -"te%er
=im c9 >s -"te%er, cH >s -"te%er, cA >s -"te%er
=im cc >s -"te%er, 4Ma) >s -"te%er, ccMa) >s -"te%er
=im =ow" >s -"te%er
=im i >s Lo"%, R >s Lo"%, RMa) >s Lo"%
=im #t=ev0 >s =ou'le
=im -"&ut>rray >s Garia"t, 2ut&ut>rray >s Garia"t
=im >"swer, M>rray, E>rray
=ow" N 0
' Read i"&ut array data>rray
!e%i"6
-"&ut>rray N #electio".Galue
4Ma) N #electio".4olum"s.4ou"t
RMa) N #electio".Rows.4ou"t
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, PL#3ermuteP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 te si7e of te i"&ut array
-f 4Ma) R B Te"
Ms%!o) PTere sould 'e at least tree i"&ut colum"s.P Q
, , PL#3ermuteP
("d
("d -f
-f 4Ma) I * Te"
Ms%!o) PTis macro ca" o"ly a"dleP ? 4r(1B) ? Q
Psi) i"de&e"de"t &arameters.P, , PL#3ermuteP
("d
("d -f
-f RMa) R 4Ma) J 1 Te"
Ms%!o) PTere are too few rows for te "um+P ? Q
4r(1B) ? P'er of i"de&e"de"t &arameters used.P, Q
, PL#3ermuteP
("d
("d -f
' 4ec1 for missi"% i"&ut data
0or i N 1 To RMa)
-f -s(m&ty(-"&ut>rray(i, 1)) Te"
Ms%!o) PE+value(s) missi"%P, , PL#3ermuteP
("d
("d -f
:e)t i
0or , N 2 To 4Ma)
0or i N 1 To RMa)
-f -s(m&ty(-"&ut>rray(i, ,)) Te"
Ms%!o) PM+value(s) missi"%P, , PL#3ermuteP
("d
("d -f
:e)t i
:e)t ,
' =ime"sio" te data array a"d te out&ut array
Re=im 2ut&ut>rray(1 To RMa), 1 To 4Ma))
Re=im E>rray(1 To RMa), 1 To 1) >s =ou'le
Re=im M>rray(1 To RMa), 1 To 1) >s =ou'le
' 0ill y>rray
0or R N 1 To RMa)
E>rray(R, 1) N -"&ut>rray(R, 1)
:e)t R
' -"itiali7e )>rray
0or R N 1 To RMa)
0or 4 N 1 To 4Ma)
2ut&ut>rray(R, 4) N PP
:e)t 4
:e)t R
#electio".2ffset(RMa) J 1, 0).#elect
=ow" N =ow" J RMa) J 1
' $rite colum" eadi"%s
2ut&ut>rray(1, 1) N P#ta"dard deviatio" of fitP
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
2ut&ut>rray(1, 1) N P-"dices6P
2ut&ut>rray(1, 2) N PTru 0P
2ut&ut>rray(1, B) N P8e"eralP
#electio".Galue N 2ut&ut>rray
#electio".2ffset(2, 0).#elect
=ow" N =ow" J B
' 4om&ute te out&ut for 1 varia'le6
ccMa) N 9
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, 1) N 4 + 1
2ut&ut>rray(1, 2) N #t=ev0
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, B) N #t=ev0
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for 2 varia'les6
ccMa) N H
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1
2ut&ut>rray(1, 2) N #t=ev0
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, B) N #t=ev0
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for B varia'les6
ccMa) N A
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
M>rray(R, 9) N -"&ut>rray(R, cB)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1 ? P,P ? cB + 1
2ut&ut>rray(1, 2) N #t=ev0
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, B) N #t=ev0
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for 9 varia'les6
ccMa) N *
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or c9 N cB J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
M>rray(R, 9) N -"&ut>rray(R, cB)
M>rray(R, H) N -"&ut>rray(R, c9)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1 ? Q
P,P ? cB + 1 ? P,P ? c9 + 1
2ut&ut>rray(1, 2) N #t=ev0
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, B) N #t=ev0
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t c9
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for H varia'les6
ccMa) N K
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or c9 N cB J 1 To 4Ma)
0or cH N c9 J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 2) N -"&ut>rray(R, 4)
M>rray(R, B) N -"&ut>rray(R, c2)
M>rray(R, 9) N -"&ut>rray(R, cB)
M>rray(R, H) N -"&ut>rray(R, c9)
M>rray(R, A) N -"&ut>rray(R, cH)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? c2 + 1 ? Q
P,P ? cB + 1 ? P,P ? c9 + 1 ? P,P ? cH + 1
2ut&ut>rray(1, 2) N #t=ev0
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, B) N #t=ev0
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t cH
:e)t c9
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
' 4om&ute te out&ut for A varia'les6
ccMa) N @
Re=im M>rray(1 To RMa), 1 To ccMa)) >s =ou'le
0or 4 N 2 To 4Ma)
0or c2 N 4 J 1 To 4Ma)
0or cB N c2 J 1 To 4Ma)
0or c9 N cB J 1 To 4Ma)
0or cH N c9 J 1 To 4Ma)
0or cA N cH J 1 To 4Ma)
0or R N 1 To RMa)
M>rray(R, 1) N 0
M>rray(R, 4) N -"&ut>rray(R, 2)
M>rray(R, c2) N -"&ut>rray(R, B)
M>rray(R, cB) N -"&ut>rray(R, 9)
M>rray(R, c9) N -"&ut>rray(R, H)
M>rray(R, cH) N -"&ut>rray(R, A)
M>rray(R, cA) N -"&ut>rray(R, *)
:e)t R
4all LL##(ccMa), RMa), 0, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, 1) N 4 + 1 ? P,P ? Q
P,P ? c2 + 1 ? P,P ? cB + 1 ? P,P ? Q
c9 + 1 ? cH + 1 ? P,P ? cA + 1
2ut&ut>rray(1, 2) N #t=ev0
0or R N 1 To RMa)
M>rray(R, 1) N 1
:e)t R
4all LL##(ccMa), RMa), 1, E>rray, M>rray, #t=ev0)
2ut&ut>rray(1, B) N #t=ev0
#electio".Galue N 2ut&ut>rray
#electio".2ffset(1, 0).#elect
=ow" N =ow" J 1
:e)t cA
:e)t cH
:e)t c9
:e)t cB
:e)t c2
:e)t 4
#electio".2ffset(+=ow", 0).#elect
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''****************''''''''''''''''''''''
'''''''''''''''''''''* *''''''''''''''''''''''
'''''''''''''''''''''* LLSS *''''''''''''''''''''''
'''''''''''''''''''''* *''''''''''''''''''''''
'''''''''''''''''''''****************''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& LLSS(ccMa), RMa), 3, E>rray, M>rray, #t=ev0)
' Tis su'routi"e &rovides te sta"dard deviatio" #t=ev0
' of te least squares fit. -t calls te su'routi"es
' -"vert, Multi&ly, a"d Tra"s&ose.
=im 't>rray, 'tq>rray
=im ##R >s =ou'le, varE >s =ou'le
=im &>rray, &i>rray, q>rray
=im )t>rray, yt>rray, yty>rray
Re=im yt>rray(1 To 1, 1 To RMa)) >s =ou'le
Re=im yty>rray(1 To 1, 1 To 1) >s =ou'le
Re=im )t>rray(1 To ccMa), 1 To RMa)) >s =ou'le
Re=im &>rray(1 To ccMa), 1 To ccMa)) >s =ou'le
Re=im &i>rray(1 To ccMa), 1 To ccMa)) >s =ou'le
Re=im q>rray(1 To ccMa), 1 To 1) >s =ou'le
Re=im '>rray(1 To ccMa), 1 To 1) >s =ou'le
Re=im 't>rray(1 To 1, 1 To ccMa)) >s =ou'le
Re=im 'tq>rray(1 To 1, 1 To 1) >s =ou'le
' 4om&ute te least squares fit
4all Tra"s&ose(M>rray, RMa), ccMa), )t>rray)
4all Multi&ly()t>rray, ccMa), RMa), M>rray, ccMa), &>rray)
4all -"vert(&>rray, ccMa), &i>rray)
4all Multi&ly()t>rray, ccMa), RMa), E>rray, 1, q>rray)
4all Multi&ly(&i>rray, ccMa), ccMa), q>rray, 1, '>rray)
4all Tra"s&ose(E>rray, RMa), 1, yt>rray)
4all Tra"s&ose('>rray, ccMa), 1, 't>rray)
4all Multi&ly(yt>rray, 1, RMa), E>rray, 1, yty>rray)
4all Multi&ly('t>rray, 1, ccMa), q>rray, 1, 'tq>rray)
' 4om&ute te sta"dard deviatio" of te fit
##R N yty>rray(1, 1) + 'tq>rray(1, 1)
varE N ##R C (RMa) + ccMa) + 3 J B)
#t=ev0 N #qr(>'s(varE))
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''*********************************'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''* Sol%erAid *'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''*********************************'''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' #olver>id ta1es te results of #olver a"d com&utes te
' corres&o"di"% sta"dard deviatio"s, i"cludi"% color codi"%
' i" case te a'solute value of aiCsi is close to 1.
' $e" tere are multi&le &arameters, te macro dis&lays
' te covaria"ce matri), 4M, i" dar1 'lue italics, a"d
' &rovides te o&tio" to sow te corres&o"di"% array of
' li"ear correlatio" coefficie"ts, 44, color+coded to alert
' te user i" case of colli"earity.
' >ll "ecessary derivatives are com&uted wit seco"d+order
' ce"tral differe"ci"%.
' R(S5-R(M(:T#6
' Tis macro requires te su'routi"e -"vert
' -:35T6
' Te i"&ut i"formatio" must 'e &rovided i" res&o"se to
' tree i"&ut 'o)es, wic as1 for (1) te locatio" of
' te #-:8L( 4(LL or 42:T-8525# 42L5M: co"tai"i"% te
' &arameter(s) determi"ed 'y #olver< (2) te locatio" of
' te cell co"tai"i"% te tar%et to 'e mi"imi7ed, suc
' as ##R< a"d (B) te 42:T-8525# 42L5M: co"tai"i"% te y+
' values calculated wit te #olver+determi"ed &arameters.
' :ote tat tese data must co"tai" te formulas referri"%
' to te #olver+determi"ed &arameters< a colum" merely
' co"tai"i"% teir "umerical values will :2T do.
' 0or co"ve"ie"t out&ut, &lace te tar%et (e.%., ##R) suc
' tat tere is a" em&ty cell directly a'ove it for te
' macro la'el, a"d a" em&ty cell to its immediate ri%t for
' te sta"dard deviatio" of te fit of te fu"ctio", #f.
' Li1ewise leave em&ty cells to te ri%t of te #olver
' &arameters for teir i"dividual sta"dard deviatio"s. -f
' tis is "ot do"e, messa%e 'o)es will dis&lay te out&ut.
' 25T35T6
' 3rovided tat tese s&aces are u"occu&ied, te sta"dard
' deviatio"s of te fit, a"d te sta"dard deviatio"(s) of
' te &arameter(s), will 'e &laced directly, i" italics, to
' te ri%t of te corres&o"di"% &arameters (we" tese
' were e"tered as a colum"), or 'elow tem (for row i"&ut).
' 2terwise, te result(s) will 'e dis&layed i" messa%e
' 'o)es. -t is terefore most co"ve"ie"t to leave 'la"1
' te s&readseet cells to te ri%t of (or 'elow) te
' &arameters a"d of ##R.
' $ar"i"%6 -f s&ace to 'e used for out&ut co"tai"s te)t or
' oter "o"+"umerical i"formatio" (suc as time or date),
' te macro will cras.
' Te covaria"ce matri) sows te varia"ces o" its mai"
' (to&+left to 'ottom+ri%t) dia%o"al, a"d te corres&o"+
' di"% covaria"ces i" te off+dia%o"al &ositio"s. Te user
' must s&ecify were o" te s&readseet it sould 'e dis+
' &layed. -f you do "ot wis to see te covaria"ce matri)
' a"d te corres&o"di"% li"ear correlatio" coefficie"ts,
' select P4a"celP we" as1ed to s&ecify te locatio" of
' te covaria"ce matri).
' Te user also s&ecifies te locatio" o" te s&readseet
' of te o&tio"al array of te correlatio" coefficie"ts,
' for wic all eleme"ts o" te mai" dia%o"al are 1, a"d
' all off+dia%o"al eleme"ts are calculated as r(i,,) N
' v(i,,)CsqrX(v(i,i)*v(,,,)Y.
' 3R24(=5R(6
' To start te &rocess, call te macro, a"d e"ter or
' dra% te requested addresses i"to te i"&ut 'o)es.
' 42L2R 42=(# 5#(=6
' > color code is used wit te sta"dard deviatio" # of
' a &arameter 3, i" order to alert te user we" tat
' sta"dard deviatio" is "ot muc smaller ta" te a'solute
' value of tat &arameter. Te color code used is6
' 'lac1 for >'s(3C#) I H
' %ray for B R >'s(3C#3) RN H
' ora"%e for 2 R >'s(3C#3) RN B
' red for 1 R >'s(3C#3) RN 2
' 'old red for >'s(3C#3) RN 1
' > color code is also used wit te array of li"ear
' correlatio" coefficie"ts 44, to alert te user to
' colli"earity. -" tis case te color code used is6
' 'lac1 for a's(44) R 0.@0
' %ray for 0.@0 RN a's44 R 0.@H
' ora"%e for 0.@H RN a's44 R 0.@K
' red for 0.@K RN a's44 R 0.@@
' 'old red for 0.@@ RN a's44 R 1
' -" 'ot cases, a cell comme"t summari7i"% te color
' code used is attaced to te dis&lay.
' (M>M3L(#6
' 5se of tis macro is illustrated trou%out >(B, starti"%
' wit ca&ter 9.
Su& Sol%erAid()
' :2T>T-2: 5#(=6
' 36 si"%le 3arameter determi"ed 'y #olver,
' 336 multi&le 3arameters determi"ed 'y #olver
' wic must 'e i" a si"%le, co"ti%uous colum".
' #06 te #ta"dard deviatio" o" te 0u"ctio"
' #36 te #ta"dard deviatio"s of a si"%le 3arameter
' #336 te #ta"dard deviatio"s of multi&le 3arameters
' T6 te #olver Tar%et (e.%., te sum of squares
' of te residuals) used i" o&timi7i"% #olver
' Ecalc6 te E+values com&uted wit te &arameters 3,
' wic must 'e i" a co"ti%uous si"%le colum"
' &refi)es used6
' a6 te address of
' c6 te "um'er of colum"s of
' o6 occu&a"cy i"de) (06 em&ty, 16 occu&ied)
' r6 te "um'er of rows of
' r%6 te ra"%e of
' suffi)es used6
' a6 >'ove
' m]6 Mi"us ] times =elta
' &]6 3lus ] times =elta
' r6 to te Ri%t
' =ime"sio" te &arameters
=im c3 >s -"te%er, cT >s -"te%er, cE >s -"te%er
=im i >s -"te%er, ii >s -"te%er, : >s -"te%er
=im o3r >s -"te%er
=im oTa >s -"te%er, oTr >s -"te%er
=im r3 >s -"te%er, rT >s -"te%er
=im , >s Lo"%, rE >s Lo"%, rrE >s Lo"%
=im =elta >s =ou'le
=im 3 >s =ou'le, 3m1 >s =ou'le, 3m2 >s =ou'le
=im 3&1 >s =ou'le, 3&2 >s =ou'le, 3r >s =ou'le
=im S >s =ou'le, Root >s =ou'le, #f >s =ou'le, #==1 >s =ou'le
=im #3 >s =ou'le, t >s =ou'le, Z >s =ou'le
=im cc >s Garia"t, 4oGar >s Garia"t
=im 34 >s Garia"t, 34s >s Garia"t
=im 33 >s Garia"t, 33m1 >s Garia"t, 33m2 >s Garia"t
=im 33&1 >s Garia"t, 33&2 >s Garia"t, 33r >s Garia"t
=im SS >s Garia"t, #33 >s Garia"t
=im E >s Garia"t, Em1 >s Garia"t, Em2 >s Garia"t
=im E&1 >s Garia"t, E&2 >s Garia"t
=im r%3 >s Ra"%e, r%T >s Ra"%e
=im r%E >s Ra"%e, r%4M >s Ra"%e
=im >"swer, i>"swer, ii>"swer, aLeftTo&, aRi%t!ottom
=im s, Try>%ai">, Try>%ai"!, Try>%ai"4, Try>%ai"=
=im LastLi"e
=elta N 0.0000B
' #elect te com&uted #olver &arameter 31 or &arameters
#et r%3 N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe locatio" of te cell or colum" co"tai"i"%P ? Q
4r(1B) ? Pte &arameter(s) determi"ed 'y #olver is6P, Q
Title6NP#olver>id i"&ut6 #olver &arameter(s)P, Ty&e6NK)
r%3.#elect
c3 N #electio".4olum"s.4ou"t
r3 N #electio".Rows.4ou"t
-f c3 N 0 Te" ("d
' Multi&le &arameters must 'e i" a si"%le colum"
-f c3 I 1 Te"
Ms%!o) PTe #olver+determi"ed &arameterP ? 4r(1B) ? Q
Pmust 'e i" a co"ti%uous #-:8L( 42L5M:.P
("d
("d -f
' Read te multi&le &arameters
' a"d dime"sio" te related varia'les
-f r3 I 1 Te"
v&3 N #electio".Galue ' readi"%
f33 N #electio".0ormula ' readi"%
33m2 N #electio".Galue ' dime"sio"i"%
33m1 N #electio".Galue ' dime"sio"i"%
33&1 N #electio".Galue ' dime"sio"i"%
33&2 N #electio".Galue ' dime"sio"i"%
("d -f
' Te colum" of multi&le &arameters must 'e co"ti%uous
-f r3 I 1 Te"
: N 0
0or i N 1 To r3
-f -s(m&ty(f33(i, 1)) Te" : N : J 1
:e)t i
-f : I 0 Te"
Ms%!o) PTe #olver+determi"ed &arametersP ? 4r(1B) Q
? Pmust 'e i" a 42:T-8525# si"%le colum".P
("d
("d -f
("d -f
Re=im #33(1 To r3, 1 To c3)
Re=im SS(1 To r3, 1 To c3)
' Re&lace a"y 7eros i" te i"&ut &arameters 'y
' small "o"+7ero "um'ers, i" order to &reve"t
' su'seque"t divide+'y+7ero errors
-f r3 N 1 Te"
3 N #electio".Galue
-f 3 N 0 Te" 3 N 1(+B00
(lse-f r3 I 1 Te"
0or i N 1 To r3
-f v&3(i, 1) N 0 Te" v&3(i, 1) N 1(+B00
:e)t i
("d -f
' Test te default out&ut ra"%e for te sta"dard
' deviatio"s #3 to te ri%t of te &arameter(s) 3.
o3r N 0
#electio".2ffset(0, 1).#elect
-f r3 N 1 Te"
3r N #electio".Galue
-f (-s(m&ty(3r) 2r 3r N 0) Te"
o3r N o3r
(lse
o3r N 1
("d -f
(lse-f r3 I 1 Te"
33r N #electio".Galue
0or i N 1 To r3
-f -s(m&ty(33r(i, 1)) Te"
o3r N o3r
(lse
o3r N 1
("d -f
:e)t i
("d -f
#electio".2ffset(0, +1).#elect
' #elect te #olver tar%et, suc as
' te sum of squares of te residuals
#et r%T N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe #olver Tar%et (suc as te sum ofP ? Q
4r(1B) ? Psquares of te residuals) is located i"6 P, Q
Title6NP#olver>id i"&ut6 Tar%etP, Ty&e6NK)
r%T.#elect
cT N #electio".4olum"s.4ou"t
rT N #electio".Rows.4ou"t
-f cT RI 1 Te" ("d
-f rT RI 1 Te" ("d
t N #electio".Galue
' Test te default out&ut ra"%e for s&ace for te
' sta"dard deviatio" of te fit to te fu"ctio",
' #f, as well as for te macro la'el
oTa N 1 ' tests cell 2ccu&a"cy >'ove T
oTr N 1 ' tests cell 2ccu&a"cy to te Ri%t of T

#electio".2ffset(0, 1).#elect
s N #electio".Galue
-f (-s(m&ty(s) 2r s N 0) Te" oTr N 0
#electio".2ffset(0, +1).#elect
2" (rror Resume :e)t ' i" case T is o" row 1
#electio".2ffset(+1, 0).#elect
-f (rr N 0 Te"
s N #electio".Galue
-f (-s(m&ty(s) 2r s N 0 2r s N P#olver>idP) Te" oTa N 0
#electio".2ffset(1, 0).#elect
("d -f
' #elect te com&uted E+values, Ecalc
#et r%E N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe colum" co"tai"i"% Ecalc is6P, Q
Title6NP#olver>id i"&ut6 EcalcP, Ty&e6NK)
r%E.#elect
rE N #electio".Rows.4ou"t
cE N #electio".4olum"s.4ou"t
-f cE RI 1 Te"
Ms%!o) PTe Ecalc values sould 'e i"P ? Q
4r(1B) ? Pa si"%le, co"ti%uous 42L5M:P
("d
("d -f
-f rE RN r3 Te"
Ms%!o) P Te "um'er : of data &airs must 'e at leastP ? Q
4r(1B) ? Plar%er 'y o"e ta" te "um'er of P Q
? P&arameters 3.P, , P#olver>idP
("d
("d -f
r%E.#elect
E N #electio".Galue ' readi"%
Em2 N #electio".Galue ' dime"sio"i"%
Em1 N #electio".Galue ' dime"sio"i"%
E&1 N #electio".Galue ' dime"sio"i"%
E&2 N #electio".Galue ' dime"sio"i"%
>&&licatio".#cree"5&dati"% N 0alse
' 3lace te macro la'el a'ove, 'elow, or o" T

r%T.#elect
-f oTa N 0 Te"
#electio".2ffset(+1, 0).#elect
$it #electio"
.Galue N P#olver>idP
.0o"t.!old N True
.0o"t.-talic N 0alse
.0o"t.4olor-"de) N H
.Dori7o"tal>li%"me"t N )l4e"ter
.-"terior.4olor-"de) N 20
("d $it
("d -f
$it #electio"
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
P#olver>id vs. *P ? 4r(10) ? Q
P3aram6 P ? r%3.>ddress ? 4r(10) ? Q
PTar%et6 P ? r%T.>ddress ? 4r(10) ? Q
PEcalc6 P ? r%E.>ddress ? 4r(10) ? Q
=ate ? P, P ? Time
("d $it
-f (oTa N 0 2r (oTa N 1 >"d #electio".Galue N Q
P#olver>idP)) Te" #electio".2ffset(1, 0).#elect
' 4om&ute a"d dis&lay te value of #f

r%T.#elect
#f N #qr(t C (rE + r3))
-f oTr N 1 Te"
>"swer N Ms%!o)(PTe cell to te ri%t of ##R isP Q
? 4r(1B) ? P"ot em&ty. 4a" it 'e overwritte"OP, v'Ees:o,
P2verwriteOP)
-f >"swer N v'Ees Te" oTr N 0
("d -f
-f oTr N 0 Te"
#electio".2ffset(0, 1).#elect
$it #electio"
.Galue N #f
.0o"t.!old N 0alse
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.Dori7o"tal>li%"me"t N )l4e"ter
.4lear4omme"ts
("d $it
#electio".2ffset(0, +1).#elect
("d -f
-f oTr N 1 Te" Ms%!o) PTe sta"dard deviatio" of P Q
? Pte fit of te fu"ctio" is P ? #f, , P#olver>idP
' Te 2:(+3>R>M(T(R case
' 4om&ute te &artial differe"tials dECd3
' a"d te sta"dard deviatio"s
-f r3 N 1 Te"
r%E.#elect
E N #electio".Galue
Em2 N #electio".Galue
Em1 N #electio".Galue
E&1 N #electio".Galue
E&2 N #electio".Galue
r%3.#elect
3 N r%3.Galue
3m2 N 3 * (1 + 2 * =elta)
3m1 N 3 * (1 + =elta)
3&1 N 3 * (1 J =elta)
3&2 N 3 * (1 J 2 * =elta)
r%3.#elect
#electio".Re&lace 3, 3m2
r%E.#elect
Em2 N r%E.Galue
r%3.#elect
#electio".Re&lace 3m2, 3m1
r%E.#elect
Em1 N r%E.Galue
r%3.#elect
#electio".Re&lace 3m1, 3&1
r%E.#elect
E&1 N r%E.Galue
r%3.#elect
#electio".Re&lace 3&1, 3&2
r%E.#elect
E&2 N r%E.Galue
r%3.#elect
#electio".Re&lace 3&2, 3

Re=im =1(1 To rE) >s =ou'le, ==1(1 To rE) >s =ou'le
#==1 N 0
0or , N 1 To rE
=1(,) N (Em2(,, 1) + E&2(,, 1) J K * Q
(E&1(,, 1) + Em1(,, 1))) C (12 * =elta * 3)
==1(,) N =1(,) * =1(,)
#==1 N #==1 J ==1(,)
:e)t ,
r%3.#elect
#electio".Galue N 3
#3 N #f C #qr(#==1)

' $rite te sta"dard deviatio" of te &arameter
-f o3r I 0 Te"
>"swer N Ms%!o)(PTe cells to te ri%t of teP Q
? 4r(1B) ? P#olver &arameter is "ot em&ty.P Q
? P4a" it 'e overwritte"OP, v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te"
0or i N 1 To r3
Ms%!o) PTe sta"dard deviatio" of teP ? Q
4r(1B) ? P&arameter is P ? #3, , P#olver>idP
:e)t i
("d -f
-f >"swer N v'Ees Te" o3r N 0
("d -f

-f o3r N 0 Te"
r%3.#elect
#electio".2ffset(0, 1).#elect
#electio".Galue N #3
S N >'s(3 C #3)

' >&&ly color code
' 4olor code used6
' 'lac1 for S I H
' %ray for B R S RN H
' ora"%e for 2 R S RN B
' red for 1 R S RN 2
' 'old red for S RN 1

$it #electio".0o"t
.-talic N True
.!old N 0alse
.4olor-"de) N 1
-f S RN H Te" .4olor-"de) N 1A
-f S RN B Te" .4olor-"de) N 9A
-f S RN B Te" .4olor-"de) N B
-f S RN 1 Te" .!old N True
("d $it

' >dd e)&la"atory cell comme"t

>ctive4ell.#elect
$it >ctive4ell
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
PS N a's(3C#)< 4olors6P ? 4r(10) ? Q
P%ray6 B R S RN HP ? 4r(10) ? Q
Pora"%e6 2 R S RN BP ? 4r(10) ? Q
Pred6 1 R S RN 2P ? 4r(10) ? Q
P'old red6 S RN 1P
("d $it

("d -f
8oTo LastLi"e
("d -f
' Te M5LT-3L(+3>R>M(T(R case
' 4om&ute te &artial differe"tials
-f r3 I 1 Te"
Re=im =(1 To r3, 1 To rE) >s =ou'le
0or i N 1 To r3
r%3.#elect
#electio".0ormula N f33
33m2(i, 1) N v&3(i, 1) * (1 + 2 * =elta)
#electio".Galue N 33m2
r%E.#elect
Em2 N #electio".Galue

r%3.#elect
33m2(i, 1) N v&3(i, 1)
#electio".0ormula N f33
33m1 N #electio".Galue
33m1(i, 1) N v&3(i, 1) * (1 + =elta)
#electio".Galue N 33m1
r%E.#elect
Em1 N #electio".Galue
r%3.#elect
#electio".0ormula N f33
33&1 N #electio".Galue
33&1(i, 1) N v&3(i, 1) * (1 J =elta)
#electio".Galue N 33&1
r%E.#elect
E&1 N #electio".Galue
r%3.#elect
#electio".0ormula N f33
33&2 N #electio".Galue
33&2(i, 1) N v&3(i, 1) * (1 J 2 * =elta)
#electio".Galue N 33&2
r%E.#elect
E&2 N #electio".Galue
r%3.#elect
#electio".0ormula N f33

0or , N 1 To rE
=(i, ,) N (Em2(,, 1) + E&2(,, 1) J K * Q
(E&1(,, 1) + Em1(,, 1))) C (12 * =elta * v&3(i, 1))
:e)t ,
:e)t i

r%3.#elect
#electio".Galue N v&3

Re=im dd(1 To r3, 1 To r3, 1 To rE) >s =ou'le
Re=im #==(1 To r3, 1 To r3) >s =ou'le
Re=im #==-"v(1 To r3, 1 To r3) >s =ou'le
0or i N 1 To r3
0or ii N 1 To r3
#==(i, ii) N 0
0or , N 1 To rE
dd(i, ii, ,) N =(i, ,) * =(ii, ,)
#==(i, ii) N #==(i, ii) J dd(i, ii, ,)
:e)t ,
:e)t ii
:e)t i

4all -"vert(#==, r3, #==-"v)
' =is&lay te sta"dard deviatio"s of te
' #olver &arameters

>&&licatio".#cree"5&dati"% N True

0or i N 1 To r3
#33(i, 1) N #f * #qr(#==-"v(i, i))
SS(i, 1) N >'s(v&3(i, 1) C #33(i, 1))
:e)t i
-f o3r I 0 Te"
>"swer N Ms%!o)(PTere are data i" te cells to te P Q
? Pri%t of teP ? 4r(1B) ? P#olver &arameters. P Q
? P4a" tey 'e overwritte"OP, v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te"
0or i N 1 To r3
Ms%!o) PTe sta"dard deviatio" ]P ? i ? Q
4r(1B) ? Pis P ? #33(i, 1), , P#olver>idP
:e)t i
("d -f
-f >"swer N v'Ees Te" o3r N 0
("d -f
-f o3r N 0 Te"
r%3.#elect
#electio".2ffset(0, 1).#elect

' >&&ly te color code 'ased o" SS,
' i.e., o" te value of a'sX3(i)C#3(i)Y, were
' te 3(i) are te #olver+determi"ed &arameters,
' a"d te #3(i) teir sta"dard deviatio"s.

' 4olor code used6
' 'lac1 for SS I H
' %ray for B R SS RN H
' ora"%e for 2 R SS RN B
' red for 1 R SS RN 2
' 'old red for SS RN 1

#electio".Galue N SS
0or (ac 4ell -" #electio".4ells
4ell.Dori7o"tal>li%"me"t N )l4e"ter
4ell.0o"t.-talic N True
-f 4ell.Galue I H Te"
4ell.0o"t.!old N 0alse
4ell.0o"t.4olor-"de) N 1 ' 'lac1
(lse-f (4ell.Galue RN H >"d 4ell.Galue I B) Te"
4ell.0o"t.!old N 0alse
4ell.0o"t.4olor-"de) N 1A ' %ray
(lse-f (4ell.Galue RN B >"d 4ell.Galue I 2) Te"
4ell.0o"t.!old N 0alse
4ell.0o"t.4olor-"de) N 9A ' ora"%e
(lse-f (4ell.Galue RN 2 >"d 4ell.Galue I 1) Te"
4ell.0o"t.!old N 0alse
4ell.0o"t.4olor-"de) N B ' red
(lse-f 4ell.Galue RN 1 Te"
4ell.0o"t.!old N True ' 'old
4ell.0o"t.4olor-"de) N B ' red
("d -f
:e)t 4ell

' 2verwrite SS wit ##3 'ut leave color code i"tact

#electio".Galue N #33

' >dd a" e)&la"atory cell comme"t

>ctive4ell.#elect
$it >ctive4ell
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
PS N a's(3C#)< 4olors6P ? 4r(10) ? Q
P%ray6 B R S RN HP ? 4r(10) ? Q
Pora"%e6 2 R S RN BP ? 4r(10) ? Q
Pred6 1 R S RN 2P ? 4r(10) ? Q
P'old red6 S RN 1P
("d $it
("d -f
' #elect te o&tio", a"d te 'loc1
' i" wic to write te matri)
Try>%ai">6

-f t N 0 Te" 8oTo LastLi"e

>&&licatio".#cree"5&dati"% N True

(rr N 0
2" (rror Resume :e)t ' >'olis 4M wit P4a"celP
#et r%4M N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe covaria"ce matri) "eeds a 'loc1P ? 4r(1B) ? Q
Pof P ? r3 ? P 'y P ? r3 ? P cells.P ? Q
P -t sould 'e located i"6P, Ty&e6NK)
-f (rr RI 0 Te" 8oTo LastLi"e
r%4M.#elect
4oGar N #electio".Galue
cc N #electio".Galue

' Ma1e sure tat te selected 'loc1 as te correct si7e

-f #electio".Rows.4ou"t RI r3 Te"
Ms%!o) PTe selected ra"%e does "ot ave P ? Q
r3 ? P rows.P ? 4r(1B) ? Q
P3us 2L a"d te" select a &ro&er 'loc1.P
8oTo Try>%ai">
("d -f
-f #electio".4olum"s.4ou"t RI r3 Te"
Ms%!o) PTe selected ra"%e does "ot ave P ? r3 ? Q
P colum"s.P ? 4r(1B) ? Q
P3us 2L a"d te" select a &ro&er 'loc1.P
8oTo Try>%ai">
("d -f

' =raw a 'o) arou"d te selected 'loc1

#electio".!orders()l(d%eTo&).Li"e#tyle N )l=as=ot=ot
#electio".!orders()l(d%eTo&).$ei%t N )lTi"
#electio".!orders()l(d%eRi%t).Li"e#tyle N )l=as=ot=ot
#electio".!orders()l(d%eRi%t).$ei%t N )lTi"
#electio".!orders()l(d%e!ottom).Li"e#tyle N Q
)l=as=ot=ot
#electio".!orders()l(d%e!ottom).$ei%t N )lTi"
#electio".!orders()l(d%eLeft).Li"e#tyle N )l=as=ot=ot
#electio".!orders()l(d%eLeft).$ei%t N )lTi"

' 0ormat cells i" array
0or (ac 4ell -" #electio".4ells
4ell.Dori7o"tal>li%"me"t N )l4e"ter
4ell.0o"t.-talic N True
4ell.0o"t.4olor-"de) N H
:e)t 4ell
' $rite te covaria"ce matri) i" te selected 'loc1

0or i N 1 To r3
0or , N 1 To r3
4oGar(i, ,) N #f * #f * #==-"v(i, ,)
:e)t ,
:e)t i
0or i N 1 To r3
0or , N 1 To r3
Root N #qr(4oGar(i, i) * 4oGar(,, ,))
cc(i, ,) N 4oGar(i, ,) C Root
:e)t ,
:e)t i

#electio".Galue N 4oGar

' La'el te 4ovaria"ce Matri)

>ctive4ell.#elect
>ctive4ell.2ffset(0, +1).#elect
-f -s(m&ty(>ctive4ell) Te"
$it >ctive4ell
.Galue N P4M6P
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N H
.-"terior.4olor-"de) N )l:o"e
.Dori7o"tal>li%"me"t N )lRi%t
("d $it
("d -f
>ctive4ell.2ffset(0, 1).#elect

' Read te default locatio", directly 'elow 4M,
' for te 4orrelatio" 4oefficie"ts
#electio".2ffset(r3, 0).#elect
>ctive4ell.#elect
aLeftTo& N #electio".>ddress
>ctive4ell.2ffset(r3 + 1, r3 + 1).#elect
aRi%t!ottom N #electio".>ddress
!o)>ddress N aLeftTo& ? P6P ? aRi%t!ottom
r%4M.#elect
' 3rovide te o&tio"al dis&lay of te
' li"ear correlatio" coefficie"ts

i>"swer N Ms%!o)(P=o you also wa"t to see teP Q
? 4r(1B) ? Pli"ear correlatio" coefficie"tsOP, Q
v'Ees:o, P#olver>idP)

Try>%ai"!6

-f i>"swer N v'Ees Te"
>&&licatio".#cree"5&dati"% N True
#et r%4M N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe array of li"ear correlatio" coefficie"tsP ? Q
Palso "eedsP ? 4r(1B) ? Pa 'loc1 of P ? r3 ? Q
P 'y P ? r3 ? P cells.P ? Q
P -t sould 'e located i"6P, =efault6N!o)>ddress, Q
Ty&e6NK)
r%4M.#elect

' Ma1e sure tat te selected 'loc1 as te correct si7e

-f #electio".Rows.4ou"t RI r3 Te"
Ms%!o) PTe selected ra"%e does "ot ave P ? Q
r3 ? P rows.P ? 4r(1B) ? Q
P3us 2L a"d te" select a &ro&er 'loc1.P
8oTo Try>%ai"!
("d -f
-f #electio".4olum"s.4ou"t RI r3 Te"
Ms%!o) PTe selected ra"%e does "ot ave P ? r3 ? Q
P colum"s.P ? 4r(1B) ? Q
P3us 2L a"d te" select a &ro&er 'loc1.P
8oTo Try>%ai"!
("d -f

' =raw a 'o) arou"d te selected 'loc1

#electio".!orders()l(d%eTo&).Li"e#tyle N )l=as=ot=ot
#electio".!orders()l(d%eTo&).$ei%t N )lTi"
#electio".!orders()l(d%eRi%t).Li"e#tyle N )l=as=ot=ot
#electio".!orders()l(d%eRi%t).$ei%t N )lTi"
#electio".!orders()l(d%e!ottom).Li"e#tyle N Q
)l=as=ot=ot
#electio".!orders()l(d%e!ottom).$ei%t N )lTi"
#electio".!orders()l(d%eLeft).Li"e#tyle N )l=as=ot=ot
#electio".!orders()l(d%eLeft).$ei%t N )lTi"

' $rite te li"ear correlatio" coefficie"ts
' i" te selected 'loc1

#electio".Galue N cc
' 0ormat a"d color+code te cells i" te 44 array
' 4olor alerts i"dicati"% colli"earity6
' 'lac1 for a's(4oGar) R 0.@0
' %ray for 0.@0 RN a's(4oGar) R 0.@H
' ora"%e for 0.@H RN a's(4oGar) R 0.@K
' red for 0.@K RN a's(4oGar) R 0.@@
' 'old red for 0.@@ RN a's(4oGar) R 1
0or (ac 4ell -" #electio".4ells
4ell.Dori7o"tal>li%"me"t N )l4e"ter
4ell.0o"t.-talic N True
4ell.0o"t.!old N 0alse
a N >'s(4ell.Galue)
-f a R 0.@ Te"
4ell.0o"t.4olor-"de) N 1 ' 'lac1
(lse-f (a IN 0.@ >"d a R 0.@H) Te"
4ell.0o"t.4olor-"de) N 1A ' %ray
(lse-f (a IN 0.@H >"d a R 0.@K) Te"
4ell.0o"t.4olor-"de) N 9A ' ora"%e
(lse-f (a IN 0.@K >"d a R 0.@@) Te"
4ell.0o"t.4olor-"de) N B ' red
(lse-f (a RI 1 >"d a IN 0.@@) Te"
4ell.0o"t.!old N True ' 'old
4ell.0o"t.4olor-"de) N B ' red
("d -f
-f 4ell.Galue N 1 Te" 4ell.0o"t.-talic N 0alse
:e)t 4ell
' La'el te li"ear correlatio" coefficie"ts
>ctive4ell.#elect
>ctive4ell.2ffset(0, +1).#elect
-f (-s(m&ty(>ctive4ell) 2r Q
>ctive4ell.Galue N P446P) Te"
$it >ctive4ell
.Galue N P446P
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.-"terior.4olor-"de) N )l:o"e
.Dori7o"tal>li%"me"t N )lRi%t
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
P4olli"earity alerts6P ? 4r(10) ? Q
P%ray6 a's44 IN 0.@0P ? 4r(10) ? Q
Pora"%e6 a's44 IN 0.@HP ? 4r(10) ? Q
Pred6 a's44 IN 0.@KP ? 4r(10) ? Q
P'old red6 a's44 IN 0.@@P
("d $it
>ctive4ell.2ffset(0, 1).#elect
(lse
>ctive4ell.2ffset(0, 1).#elect
$it >ctive4ell
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.Te)t Te)t6N Q
P4olli"earity alerts6P ? 4r(10) ? Q
P%ray6 a's44 IN 0.@0P ? 4r(10) ? Q
Pora"%e6 a's44 IN 0.@HP ? 4r(10) ? Q
Pred6 a's44 IN 0.@KP ? 4r(10) ? Q
P'old red6 a's44 IN 0.@@P
("d $it
("d -f
("d -f
("d -f
LastLi"e6
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''************************''''''''''''''''''
'''''''''''''''''* *''''''''''''''''''
'''''''''''''''''* ColumnSol%er *''''''''''''''''''
'''''''''''''''''* *''''''''''''''''''
'''''''''''''''''************************''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
'
' 4olum"#olver allows te user to a&&ly #olver seque"tially
' to data located witi" i" si"%le row, wereu&o" it moves
' to te "e)t row a"d re&eats te &rocedure.
' Te user s&ecifies te locatio" of te tar%et cells, a"d
' te locatio" of te ad,usta'le &arameter(s). Moreover,
' for 4olum"#olverGalue, te locatio" of te wa"ted tar%et
' values must 'e s&ecified. >ll i"&ut i"formatio" must 'e
' i" colum"s a"d 'loc1s of te same le"%t, wit all i"&ut
' i"formatio" for a"y i"dividual #olver a&&licatio"
' co"fi"ed to a si"%le row. $e" tere are several
' ad,usta'le &arameters, tese must 'e i" a si"%le
' co"ti%uous 'loc1.
'
' 4olum"#olverMa) ma)imi7es te value i" te tar%et cell,
' 4olum"#olverMi" mi"imi7es te value i" te tar%et cell,
' wile 4olum"#olverGalue ma1es te values of te tar%et
' cells equal to te values s&ecified i" te $a"tedGalue
' colum". Te colum" or 'loc1 of &arameter values sould
' co"tai" a&&ro&riate i"itial values for #olver, wic
' 4olum"#olver te" ca"%es i"to te fi"al &arameter values
' com&uted 'y #olver.
'
' Te level of &recisio", tolera"ce, a"d co"ver%e"ce of
' #olver, a"d all oter &refere"ces a"d co"strai"ts, sould
' 'e set i" te #olver 2&tio"s 'efore calli"% 4olum"#olver.
'
' -:35T6
'
' #et u& #olver as if for a si"%le o&eratio", i"cludi"% all
' "ecessary s&ecificatio"s of co"strai"ts a"d o&tio"s, if
' a"y. Te" call 4olum"#olver a"d a"swer te questio"s i"
' its i"&ut 'o)es. 4olum"#olver will start o"ce te "eeded
' i"&ut i"formatio" as 'ee" e"tered.
'
' 25T35T6
'
' 4olum"#olver ad,usts te &arameters so tat te tar%et cells
' yield te s&ecified criterio", Mi", Ma), or (qualToGalue.
'
' R(S5-R(M(:T#6
'
' 4olum"#olver requires tat 'ot #olver a"d #olver.)la ave
' 'ee" i"stalled.
'
' 2:(+T-M( 3R24(=5R( 02R -:#T>LL-:8 #2LG(R.ML>
'
' 4olum"#olver ca" o"ly call #olver as a su'routi"e we"
' #olver.)la is &ro&erly refere"ced i" te G!>3ro,ect.
' To see weter tis is te case, %o to te s&readseet,
' select its G!> module, a"d loo1 u"der Tools +I Refere"ces
' to see weter #2LG(R as 'ee" activated. -t sould 'e
' &art of te co"ti%uous, cec1+mar1ed to& items i" te
' listed Refere"ces + G!>3ro,ect.
'
' -f it is "ot, first &re&are your com&uter to ma1e #olver
' calla'le. Te &rocedure to do so is outli"ed 'elow, a"d
' is "eeded o"ly o"ce u"til te o&erati"% system a"dCor
' ()cel is re+i"stalled or u&dated.
'
' 4lic1 o" te #tart 'utto", a"d i" te resulti"% me"u, o"
' #earc, u"der 0or 0iles or 0olders...(or 0i"d I 0iles or
' 0olders), searc for #olver.)la. :ote dow" were
' #olver.)la is located. -f you ave Microsoft 2ffice, it
' most li1ely is i" 46^3ro%ram 0iles^Microsoft2ffice^2ffice
' ^Li'rary^#olver.
'
' ()it te #earc or 0i"d dialo% 'o), wic will 'ri"% you
' 'ac1 to te s&readseet, select te G!> editor wit
' >ltJ011, te" %o to Tools +I Refere"ces, wic will
' dis&lay te Refere"ces + G!>3ro,ect dialo% 'o). 4lic1 o"
' !rowse, select 0ilers of ty&e6 Microsoft ()cel 0iles
' (*.)ls, *.)la), a"d "ow tat you 1"ow were to fi"d it,
' "avi%ate your way to #olver, a"d 2&e" it. Tis will
' retur" you to te Refere"ces + G!>3ro,ect dialo% 'o),
' were you "ow use te 3riority 5& 'utto" to move it u&,
' so tat it is listed co"ti%uously wit te oter, already
' activated add+i"s. 4lic1 2L< from te" o" (i.e., u"til
' you reload or u&%rade ()cel) G!> will 1"ow ow to fi"d
' #olver we" it is called from a macro.
'
' (M>M3L(6
'
' 5se of tis macro is illustrated i" sectio" 9.1K of >(B.
Su& ColumnSol%erMa0()
=im = >s -"te%er
= N 1
4all 4olum"#olver(=)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ColumnSol%erMin()
=im = >s -"te%er
= N 2
4all 4olum"#olver(=)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ColumnSol%er7alue()
=im = >s -"te%er
= N B
4all 4olum"#olver(=)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ColumnSol%er(=)
=im i >s -"te%er, "c >s -"te%er, "r >s -"te%er
=im 3ositio"2f2"d=ollar >s -"te%er
=im 3arameter>ddress >s Garia"t, Row:um'er >s Garia"t
=im Tar%et>ddress >s Garia"t, $a"tedGalue >s Garia"t
=im myRow >s Ra"%e, 3arameterRa"%e >s Ra"%e
=im Tar%etRa"%e >s Ra"%e, $a"tedGalues >s Ra"%e
=im a>>, 4ell, (qualTo, 3rom&t, Title
' Read te locatio" of te tar%et colum"
a6
3rom&t N PTe tar%et cells are located i"6P ? 4r(1B) Q
? P(Di%li%t a colum" or e"ter its address)P
Title N P4olum"#olver6 >ddress of tar%et colum"P
#et Tar%etRa"%e N >&&licatio".-"&ut!o)(3rom&t, Title, Q
Ty&e6NK)
Tar%etRa"%e.#elect
"r N #electio".Rows.4ou"t
i N 0
Re=im Tar%et>ddress(1 To "r)
0or (ac 4ell -" Tar%etRa"%e
i N i J 1
Tar%et>ddress(i) N 4ell.>ddress
:e)t 4ell
Re=im 2ut&ut>rray(1 To "r)
' Gerify tat te tar%et ra"%e is a si"%le colum"
"c N #electio".4olum"s.4ou"t
-f "c RI 1 Te"
Ms%!o) PTere ca" 'e o"ly o"e si"%le Tar%et colum"P
8oTo a
("d -f
' Read te colum" co"tai"i"% te tar%et values
!6
-f = N B Te"
3rom&t N PTe wa"ted tar%et values are located i"6P ? 4r(1B) Q
? P(Di%li%t a colum" or e"ter its address)P
Title N P4olum"#olver6 $a"ted tar%et valuesP
#et $a"tedGalues N >&&licatio".-"&ut!o)(3rom&t, Title, Q
Ty&e6NK)
$a"tedGalues.#elect
Re=im $a"tedGalue(1 To "r) >s =ou'le
i N 0
0or (ac 4ell -" $a"tedGalues
i N i J 1
$a"tedGalue(i) N 4ell.Galue
:e)t 4ell
' Gerify tat te tar%et ra"%e is a si"%le colum"
"c N #electio".4olum"s.4ou"t
-f "c RI 1 Te"
Ms%!o) PTere ca" 'e o"ly o"e si"%leP ? Q
4r(1B) ? P colum" wit tar%et valuesP
8oTo !
("d -f
("d -f
' Gerify tat te tar%et ra"%e as te correct le"%t
-f "r + #electio".Rows.4ou"t RI 0 Te"
Ms%!o) PTe colum" of tar%et values must ave teP Q
? 4r(1B) ? Psame "um'er of rows as te tar%et colum".P
8oTo !
("d -f
' Read te locatio" of te ad,usta'le &arameter colum"
46
3rom&t N PTe locatio" of te ad,usta'le &arameter(s) is6P ? Q
4r(1B) ? P(Di%li%t a colum" or 'loc1, or e"ter its address)P
Title N P4olum"#olver6 >ddress of &arameter ra"%eP
#et 3arameterRa"%e N >&&licatio".-"&ut!o)(3rom&t, Title, Q
Ty&e6NK)
3arameterRa"%e.#elect
"c N #electio".4olum"s.4ou"t
-f "c R 1 Te"
Ms%!o) PTere must 'e at least o"eP Q
? 4r(1B) ? Pcolum" of ad,usta'le &arameters.P
8oTo 4
("d -f
' Gerify tat te &arameter ra"%e as te correct le"%t
-f "r + #electio".Rows.4ou"t RI 0 Te"
Ms%!o) PTe &arameter 'loc1 must ave te sameP Q
? 4r(1B) ? P"um'er of rows as te tar%et colum".P
8oTo 4
("d -f
Re=im 3arameter>ddress(1 To "r)
>&&licatio".#cree"5&dati"% N 0alse
' 0or o"e &arameter &er row
-f "c N 1 Te"
i N 0
0or (ac 4ell -" 3arameterRa"%e
i N i J 1
3arameter>ddress(i) N 4ell.>ddress
:e)t 4ell
' Ru" #olver
0or i N 1 To "r
-f = R B Te" (qualTo N P P
-f = N B Te" (qualTo N $a"tedGalue(i)
#olver2L #et4ell6NTar%et>ddress(i), Ma)Mi"Gal6N=, Q
valueof6N(qualTo, !y4a"%e6N3arameter>ddress(i)
#olver#olve 5ser0i"is6NTrue
:e)t i
8oTo (
' 0or multi&le &arameters &er row
(lse

' 0i"d te &arameter ra"%e for te &ro&er row
' at te i"tersectio" of 3arameterRa"%e a"d myRow
Re=im 3arameter>ddress(1 To "r)
Re=im Row:um'er(1 To "r)
0or i N 1 To "r
3ositio"2f2"d=ollar N -"#tr(2, Tar%et>ddress(i), PTP)
Row:um'er(i) N Mid(Tar%et>ddress(i), 3ositio"2f2"d=ollar)
a>> N PT>P ? Row:um'er(i) ? P6P ? PT-GP ? Row:um'er(i)
#et myRow N Ra"%e(a>>)
-"tersect(3arameterRa"%e, myRow).#elect
3arameter>ddress N #electio".>ddress
' Ru" #olver
-f = R B Te" (qualTo N P P
-f = N B Te" (qualTo N $a"tedGalue(i)
#olver2L #et4ell6NTar%et>ddress(i), Ma)Mi"Gal6N=, Q
valueof6N(qualTo, !y4a"%e6N3arameter>ddress
#olver#olve 5ser0i"is6NTrue
:e)t i
("d -f
(6
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''************************''''''''''''''''''
'''''''''''''''''* *''''''''''''''''''
'''''''''''''''''* Sol%erScan *''''''''''''''''''
'''''''''''''''''* *''''''''''''''''''
'''''''''''''''''************************''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
'
' #olver#ca" uses #olver to sca" &ossi'le com'i"atio"s of
' two ad,usta'le &arameters, 3 a"d S, 'y ca"%i"% te
' i"itial %uess values tat #olver uses as its &oi"ts of
' de&arture. -ts out&ut dis&lays te value of te criterio"
' (suc as ##R) used to o&timi7e 3 a"d S.
'
' Te user s&ecifies te i"itial values, te ste& si7es to
' 'e used to vary tose i"itial values, a"d te "um'ers of
' suc ste&s. Te out&ut is &rese"ted as a" array suita'le
' for dis&lay wit Ma&&er or as a B+= &lot.
'
' #electi"% a fi"e searc %rid (i.e., ma"y small ste&s)
' i"creases te e)ecutio" time of te macro. Te macro as
' 'uilt+i" limits of 2H1 ste&s &er &arameter, 'ut usi"% far
' fewer ste&s is usually sufficie"t, a"d certai"ly ma1es
' te macro com&lete its tas1 muc faster.
'
' -:35T6
'
' #et u& #olver as if for a si"%le o&eratio", i"cludi"%
' all "ecessary s&ecificatio"s of co"strai"ts a"d o&tio"s,
' if a"y. Te" call #olver#ca" a"d a"swer te questio"s i"
' te i"&ut 'o)es. #olver#ca" will start o"ce te out&ut
' area as 'ee" s&ecified.
'
' 25T35T6
'
' Te user selects te locatio" were te out&ut array will
' a&&ear, com&lete wit to& a"d left+a"d a)is la'els for
' su'seque"t visual dis&lay wit Ma&&er or as a B+= &lot
' of ##R as a fu"ctio" of 3 a"d S, were 3 a"d S are te
' two #olver+ad,usted &arameters, a"d were 3 is &lotted
' i" te M+directio", a"d S i" te E+directio".
'
' #5!R25T-:(#6
'
' #olver#ca" requires tat 'ot #olver a"d #olver.)la
' ave 'ee" i"stalled.
'
' 2:(+T-M( 3R24(=5R( 02R -:#T>LL-:8 #2LG(R.ML>
'
' #olver#ca" ca" o"ly call #olver as a su'routi"e, we"
' #olver.)la is &ro&erly refere"ced i" te G!>3ro,ect.
' To see weter tis is te case, %o to te s&readseet,
' select its G!> module, a"d loo1 u"der Tools +I
' Refere"ces to see weter #2LG(R as 'ee" activated.
' -t sould 'e &art of te co"ti%uous, cec1+mar1ed to&
' items i" te listed Refere"ces + G!>3ro,ect. -f it is
' "ot, first &re&are your com&uter to ma1e #olver calla'le.
' Te &rocedure to do so is outli"ed 'elow, a"d is "eeded
' o"ly o"ce u"til te o&erati"% system a"dCor ()cel is
' re+i"stalled or u&dated.
'
' 4lic1 o" te #tart 'utto", a"d i" te resulti"% me"u, o"
' #earc, 0or 0iles or 0olders...(or 0i"d I 0iles or
' 0olders). -" te 0i"d6 >ll 0iles dialo% 'o), u"der te
' ta' :ame ? Locatio", i" te :ame6 wi"dow ty&e #olver.)la,
' a"d, if "ecessary, e"ter #ystemdis1X46Y i" te Loo1 i"6
' wi"dow, activate -"clude su'folders, a"d clic1 o" 0i"d
' "ow. :ote dow" were #olver.)la is located. (-f you ave
' Microsoft 2ffice, it most li1ely is i" #ystemdis1X46Y,
' 3ro%ram 0iles^Microsoft 2ffice^2ffice^Li'rary^#olver.)
' ()it te #earc or 0i"d dialo% 'o), wic will 'ri"% you
' 'ac1 to te s&readseet, select te G!(ditor wit
' >ltJ011, te" %o to Tools +I Refere"ces, wic will
' dis&lay te Refere"ces + G!>3ro,ect dialo% 'o). 4lic1 o"
' !rowse, select 0iles of ty&e6 Microsoft ()cel 0iles
' (*.)ls, *.)la), a"d "ow tat you 1"ow were to fi"d it,
' "avi%ate your way to #olver.)la, a"d 2&e" it. Tis
' will retur" you to te Refere"ces + G!>3ro,ect dialo%
' 'o), were you "ow use te 3riority u& 'utto" to move
' it u&, so tat it is listed co"ti%uously wit te oter,
' already activated add+i"s. 4lic1 2L< from te" o" (i.e.,
' u"til you reload or u&%rade ()cel) G!> will 1"ow ow to
' fi"d #olver we" it is called from a macro.
'
' (M>M3L(6
'
' 5se of tis macro is illustrated i" sectio" 9.1* of (>B.
Su& Sol%erScan()
=im "c >s -"te%er, "s >s -"te%er, "7 >s -"te%er
=im 3 >s -"te%er, 3ass2ut >s -"te%er, 3ass3 >s -"te%er
=im 3assS >s -"te%er, 3assTar%et >s -"te%er, S >s -"te%er
=im #te&:um'er3 >s -"te%er, #te&:um'erS >s -"te%er
=im -"itialGalue3 >s =ou'le, -"itialGalueS >s =ou'le
=im #te&#i7e3 >s =ou'le, #te&#i7eS >s =ou'le
=im ##R >s Garia"t, Z >s Garia"t
=im Ra"%e2ut >s Ra"%e, Ra"%e3 >s Ra"%e
=im Ra"%eS >s Ra"%e, Ra"%eTar%et >s Ra"%e
=im >ddress2ut, >ddress3, >ddressS, >ddressTar%et
=im >"swer, =efault, 3rom&t, Title
' #&ecify te locatio" of te Tar%et criterio"
3rom&t N P("ter a 4(LL >==R(##6P ? 4r(1B) ? 4r(1B) ? Q
PTe tar%et cell (co"tai"i"% te o&ti+P Q
? 4r(1B) ? Pmi7atio" criterio") is located i"6P
Title N P#olver#ca"6 >ddress of tar%et cellP
#et Ra"%eTar%et N >&&licatio".-"&ut!o)(3rom&t, Title, Ty&e6NK)
Ra"%eTar%et.#elect
>ddressTar%et N Ra"%eTar%et.>ddress
##R N Ra"%eTar%et.Galue
3ass3 N 1
>36
' Read te address of te first ad,usta'le &arameter, 3
3rom&t N P("ter a 4(LL >==R(##6P ? 4r(1B) ? 4r(1B) ? Q
PTe first ad,usta'le &arameter, 3, is located i"6P
Title N P#olver#ca"6 >ddress of 3P
-f 3ass3 N 1 Te" =efault N P P
-f 3ass3 I 1 Te" =efault N Ra"%e3.>ddress
#et Ra"%e3 N >&&licatio".-"&ut!o)(3rom&t, Title, =efault,
Ty&e6NK)
Ra"%e3.#elect
>ddress3 N Ra"%e3.>ddress
' #&ecify te i"itial %uess value for 3
3rom&t N P("ter a value6P ? 4r(1B) ? 4r(1B) ? Q
PTe i"itial value of 3 is6P
Title N P#olver#ca"6 -"itial value of 3P
-f 3ass3 N 1 Te" =efault N P P
-f 3ass3 I 1 Te" =efault N -"itialGalue3
-"itialGalue3 N -"&ut!o)(3rom&t, Title, =efault)
' #&ecify te ste& si7e for 3
3rom&t N P("ter a value6P ? 4r(1B) ? 4r(1B) ? Q
PTe ste& si7e for 3 is6P
Title N P#olver#ca"6 #te& si7e for 3P
-f 3ass3 N 1 Te" =efault N P P
-f 3ass3 I 1 Te" =efault N #te&#i7e3
#te&#i7e3 N >&&licatio".-"&ut!o)(3rom&t, Title, =efault)
' #&ecify te "um'er of ste&s for 3
3rom&t N P("ter a value6P ? 4r(1B) ? 4r(1B) ? Q
PTe "um'er of ste&s for 3 is6P
Title N P#olver#ca"6 #te& "um'er for 3P
-f 3ass3 N 1 Te" =efault N P P
-f 3ass3 I 1 Te" =efault N #te&:um'er3
#te&:um'er3 N >&&licatio".-"&ut!o)(3rom&t, Title, =efault)
3ass3 N 3ass3 J 1
' 4ec1 tat #te&:um'er3 is smaller ta" 2H2
-f #te&:um'er3 I 2H1 Te"
Ms%!o) PTe "um'er of ste&s ca""ot 'e lar%er ta" 2H1.P
8oTo >3
("d -f
3assS N 1
>S6
' Read te address of te first ad,usta'le &arameter, S
3rom&t N P("ter a 4(LL >==R(##6P ? 4r(1B) ? 4r(1B) ? Q
PTe first ad,usta'le &arameter, S, is located i"6P
Title N P#olver#ca"6 >ddress of SP
-f 3assS N 1 Te" =efault N PP
-f 3assS I 1 Te" =efault N Ra"%eS.>ddress
#et Ra"%eS N >&&licatio".-"&ut!o)(3rom&t, Title, Q
=efault, Ty&e6NK)
Ra"%eS.#elect
>ddressS N Ra"%eS.>ddress
' #&ecify te i"itial %uess value for S
3rom&t N P("ter a value6P ? 4r(1B) ? 4r(1B) ? Q
PTe i"itial value of S is6P
Title N P#olver#ca"6 -"itial value of SP
-f 3assS N 1 Te" =efault N PP
-f 3assS I 1 Te" =efault N -"itialGalueS
-"itialGalueS N -"&ut!o)(3rom&t, Title, =efault)
' #&ecify te ste& si7e for S
3rom&t N P("ter a value6P ? 4r(1B) ? 4r(1B) ? Q
PTe ste& si7e for S is6P
Title N P#olver#ca"6 #te& si7e for SP
-f 3assS N 1 Te" =efault N P P
-f 3assS I 1 Te" =efault N #te&#i7eS
#te&#i7eS N >&&licatio".-"&ut!o)(3rom&t, Title, =efault)
' #&ecify te "um'er of ste&s for S
3rom&t N P("ter a value6P ? 4r(1B) ? 4r(1B) ? Q
PTe "um'er of ste&s for S is6P
Title N P#olver#ca"6 #te& "um'er for SP
-f 3assS N 1 Te" =efault N P P
-f 3assS I 1 Te" =efault N #te&:um'erS
#te&:um'erS N >&&licatio".-"&ut!o)(3rom&t, Title, =efault)
3assS N 3assS J 1
' 4ec1 tat #te&:um'erS is smaller ta" 2H2
-f #te&:um'erS I 2H1 Te"
Ms%!o) PTe "um'er of ste&s ca""ot 'e lar%er ta" 2H1.P
8oTo >S
("d -f
' #&ecify te to& left+a"d cor"er of te 2ut&ut array
3ass2ut N 1
>2ut6
3rom&t N PTe out&ut array, i"cludi"% its a)es, P Q
? Pwill 'eP ? 4r(1B) ? #te&:um'er3 J 1 Q
? P colum"s wide, a"d P ? #te&:um'erS J 1 Q
? P rows i%.P ? 4r(1B) ? Q
P ("ter a 4(LL >==R(##6P ? 4r(1B) Q
? PTe to& left+a"d cor"er of te out&utP ? 4r(1B) Q
? Parray sould 'e located at6P
Title N P#olver#ca"6 To& left+a"d cor"er of out&ut arrayP
-f 3ass2ut N 1 Te" =efault N P P
-f 3ass2ut I 1 Te" =efault N Ra"%e2ut.>ddress
#et Ra"%e2ut N >&&licatio".-"&ut!o)(3rom&t, Title, Ty&e6NK)
Ra"%e2ut.#elect
>ddress2ut N Ra"%e2ut.>ddress
3ass2ut N 3ass2ut J 1
' 4ou"t te "um'er of colum"s "c to te left of Ra"%e2ut
"c N 0
>(d%e6
2" (rror 8oTo 2"(d%e
#electio".2ffset(0, +1).#elect
"c N "c J 1
8oTo >(d%e
2"(d%e6
Ra"%e2ut.#elect
' Ma1e sure tat tere is e"ou% s&ace for te out&ut array

-f "c J #te&:um'er3 I 2H9 Te"
Ms%!o) PMove te left+a"d cor"er of teP ? Q
4r(1B) ? Pout&ut array to te left, i" orderP ? Q
4r(1B) ? Pto accommodate its &ro,ected si7e.P
8oTo >2ut
("d -f
' Gerify tat te out&ut will "ot overwrite valua'le data
>&&licatio".#cree"5&dati"% N 0alse
"7 N 0
Ra"%e2ut.#elect
0or 3 N 0 To #te&:um'er3 J 1
#electio".2ffset(0, 1).#elect
0or S N 0 To #te&:um'erS J 1
#electio".2ffset(1, 0).#elect
Z N #electio".Galue
"7 N "7 J 1
-f (-s(m&ty(Z) 2r Z N :ull) Te" "7 N "7 + 1
:e)t S
:e)t 3
>&&licatio".#cree"5&dati"% N True
-f "7 I 0 Te"
>"swer N Ms%!o)(PTere are data i" te array i" wicP Q
? 4r(1B) ? Pte out&ut data will 'e writte". P Q
? P3roceedP ? 4r(1B) Q
? Pa"yway a"d overwrite tose dataOP, v'Ees:o)
-f >"swer N v':o Te" 8oTo >2ut
("d -f
>&&licatio".#cree"5&dati"% N 0alse
Re=im ##R(#te&:um'erS J 1, #te&:um'er3 J 1) >s =ou'le
' ("ter te i"itial %uess values,
' ru" #olver, a"d write out&ut file
"s N 0
0or 3 N 0 To #te&:um'er3
Ra"%e3.#elect
Ra"%e3.Galue N -"itialGalue3 J 3 * #te&#i7e3
0or S N 0 To #te&:um'erS
Ra"%eS.#elect
Ra"%eS.Galue N -"itialGalueS J S * #te&#i7eS

>&&licatio".=is&lay#tatus!ar N 0alse
#olver2L #et4ell6NPaddressTar%etP, Ma)Mi"Gal6N2, Q
!y4a"%e6NPaddress3, addressSP
#olver#olve 5ser0i"is6NTrue

Ra"%eTar%et.#elect
##R(S, 3) N Ra"%eTar%et.Galue
"s N "s J 1
>&&licatio".=is&lay#tatus!ar N True
>&&licatio".#tatus!ar N P#olver#ca" as com&leted P ? Q
"s ? P out of P ? (#te&:um'er3 J 1) * Q
(#te&:um'erS J 1) ? P calculatio"s.P
:e)t S
:e)t 3
' $rite te a)is scale la'els
Ra"%e2ut.#elect
0or 3 N 1 To #te&:um'er3 J 1
#electio".2ffset(0, 3).#elect
#electio".Galue N -"itialGalue3 J (3 + 1) * #te&#i7e3
>ctive4ell.0o"t.-talic N True
>ctive4ell.0o"t.!old N True
#electio".2ffset(0, +3).#elect
:e)t 3
0or S N 1 To #te&:um'erS J 1
#electio".2ffset(S, 0).#elect
>ctive4ell.0o"t.-talic N True
>ctive4ell.0o"t.!old N True
#electio".Galue N -"itialGalueS J (S + 1) * #te&#i7eS
#electio".2ffset(+S, 0).#elect
:e)t S
' 2ut&ut te ##R data
Ra"%e2ut.#elect
0or 3 N 0 To #te&:um'er3
0or S N 0 To #te&:um'erS
#electio".2ffset(S J 1, 3 J 1).#elect
#electio".Galue N ##R(S, 3)
#electio".2ffset(+S + 1, +3 + 1).#elect
:e)t S
:e)t 3
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''******************'''''''''''''''''''
''''''''''''''''''''''* *'''''''''''''''''''
''''''''''''''''''''''* In%ert *'''''''''''''''''''
''''''''''''''''''''''* *'''''''''''''''''''
''''''''''''''''''''''******************'''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& In%ert(m, "rc, M-"v)
' Te square i"&ut a"d out&ut matrices are M a"d M-"v
' res&ectively< "rc is te "um'er of rows a"d colum"s i"
' M a"d M-"v

=im i >s -"te%er, icol >s -"te%er, irow >s -"te%er
=im , >s -"te%er, 1 >s -"te%er, L >s -"te%er, LL >s -"te%er
=im 'i% >s =ou'le, dummy >s =ou'le
=im : >s -"te%er, &ivi"v >s =ou'le
=im u >s =ou'le
: N "rc J 1
Re=im ''(1 To :, 1 To :) >s =ou'le
Re=im i&ivot(1 To :) >s =ou'le
Re=im -"de)(1 To :) >s =ou'le
Re=im i"de)r(1 To :) >s =ou'le
Re=im i"de)c(1 To :) >s =ou'le
u N 1
' 4o&y te i"&ut matri) i" order to retai" it
0or i N 1 To "rc
0or , N 1 To "rc
M-"v(i, ,) N m(i, ,)
:e)t ,
:e)t i
' Te followi"% is te 8auss+_orda" elimi"atio" routi"e
' 8>5##_ from _. 4. #&rott, P:umerical Reci&es6 Routi"es
' a"d ()am&les i" !>#-4P, 4am'rid%e 5"iversity 3ress,
' 4o&yri%t (4)1@@1 'y :umerical Reci&es #oftware. 5sed 'y
' &ermissio". 5se of tis routi"e oter ta" as a" i"te%ral
' &art of te &rese"t 'oo1 requires a" additio"al lice"se
' from :umerical Reci&es #oftware. 0urter distri'utio" is
' &roi'ited. Te routi"e as 'ee" modified to yield
' dou'le+&recisio" results.
0or , N 1 To "rc
i&ivot(,) N 0
:e)t ,
0or i N 1 To "rc
'i% N 0
0or , N 1 To "rc
-f i&ivot(,) RI u Te"
0or 1 N 1 To "rc
-f i&ivot(1) N 0 Te"
-f >'s(M-"v(,, 1)) IN 'i% Te"
'i% N >'s(M-"v(,, 1))
irow N ,
icol N 1
("d -f
(lse-f i&ivot(1) I 1 Te" ()it #u'
("d -f
:e)t 1
("d -f
:e)t ,
i&ivot(icol) N i&ivot(icol) J 1
-f irow RI icol Te"
0or L N 1 To "rc
dummy N M-"v(irow, L)
M-"v(irow, L) N M-"v(icol, L)
M-"v(icol, L) N dummy
:e)t L
0or L N 1 To "rc
dummy N ''(irow, L)
''(irow, L) N ''(icol, L)
''(icol, L) N dummy
:e)t L
("d -f
i"de)r(i) N irow
i"de)c(i) N icol
-f M-"v(icol, icol) N 0 Te" ()it #u'
&ivi"v N u C M-"v(icol, icol)
M-"v(icol, icol) N u
0or L N 1 To "rc
M-"v(icol, L) N M-"v(icol, L) * &ivi"v
''(icol, L) N ''(icol, L) * &ivi"v
:e)t L
0or LL N 1 To "rc
-f LL RI icol Te"
dummy N M-"v(LL, icol)
M-"v(LL, icol) N 0
0or L N 1 To "rc
M-"v(LL, L) N M-"v(LL, L) + M-"v(icol, L) * dummy
''(LL, L) N ''(LL, L) + ''(icol, L) * dummy
:e)t L
("d -f
:e)t LL
:e)t i
0or L N "rc To 1 #te& +1
-f i"de)r(L) RI i"de)c(L) Te"
0or 1 N 1 To "rc
dummy N M-"v(1, i"de)r(L))
M-"v(1, i"de)r(L)) N M-"v(1, i"de)c(L))
M-"v(1, i"de)c(L)) N dummy
:e)t 1
("d -f
:e)t L
(rase i"de)c, i"de)r, i&ivot
("d #u'
''''''''''''''''''''********************'''''''''''''''''''
''''''''''''''''''''* *'''''''''''''''''''
''''''''''''''''''''* Multiply *'''''''''''''''''''
''''''''''''''''''''* *'''''''''''''''''''
''''''''''''''''''''********************'''''''''''''''''''
Su& Multiply(M1, r1, 41, M2, c2, M2ut)
' 4om&utes te &roduct of two matrices6 M2ut N M1 times M2
' r16 "um'er of rows i" M1
' c16 "um'er of colum"s i" M1
' c26 "um'er of colum"s i" M2
' M2 must ave c1 rows
' M2ut will ave r1 rows a"d c2 colum"s
=im , >s -"te%er
=im i >s Lo"%, 1 >s Lo"%
0or i N 1 To r1
0or , N 1 To c2
M2ut(i, ,) N 0
0or 1 N 1 To 41
M2ut(i, ,) N M2ut(i, ,) J M1(i, 1) * M2(1, ,)
:e)t 1
:e)t ,
:e)t i
("d #u'
''''''''''''''''''''********************'''''''''''''''''''
''''''''''''''''''''* *'''''''''''''''''''
''''''''''''''''''''* 7Multiply *'''''''''''''''''''
''''''''''''''''''''* *'''''''''''''''''''
''''''''''''''''''''********************'''''''''''''''''''
Su& 7Multiply(m, R, 4, G, M2ut)
' Tis fu"ctio" com&utes te &roduct of te matri) M
' a"d te dia%o"al matri) =M, were te latter as 'ee"
' co"de"sed i"to a vector G
' were6 M2ut N M times =M
' r6 "um'er of rows i" M
' c6 "um'er of colum"s i" M
' G must ave c eleme"ts
' M2ut will ave r rows a"d c colum"s
=im i >s Lo"%, , >s -"te%er, 1 >s -"te%er
0or i N 1 To R
0or , N 1 To 4
M2ut(i, ,) N m(i, ,) * G(,)
:e)t ,
:e)t i
("d #u'
''''''''''''''''''''*********************''''''''''''''''''
''''''''''''''''''''* *''''''''''''''''''
''''''''''''''''''''* Transpose *''''''''''''''''''
''''''''''''''''''''* *''''''''''''''''''
''''''''''''''''''''*********************''''''''''''''''''
Su& Transpose(m, R, 4, MT)
' 4om&utes te tra"s&ose MT of matri) M
' r6 "um'er of rows i" M
' c6 "um'er of colum"s i" M
' MT will ave c rows a"d r colum"s
=im i >s Lo"%, , >s Lo"%
0or i N 1 To 4
0or , N 1 To R
MT(i, ,) N m(,, i)
:e)t ,
:e)t i
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''*********************************'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''* Fourier Trans#ormation *'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''*********************************'''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te macros 0orward0T a"d -"verse0T &erform fast 0ourier
' tra"sformatio"s o" a" array of com&le) data, arra"%ed i"
' a si"%le 'loc1 of tree ad,ace"t colum"s.
' #5!R25T-:(#6
' Te macros are merely drivers tat set i#i%" to J1 (for
' te forward tra"sform) or to +1 (for i"verse tra"sforma+
' tio"). Te mai" su'routi"e 0ourier te" reads te i"&ut
' i"formatio", ma1es a "um'er of cec1s, a"d com&utes te
' out&ut. 0or te actual 0ourier tra"sformatio" it te"
' calls te su'routi"e 0T. Tis latter &art is &laced i" a
' se&arate su'routi"e i" order to ma1e it readily availa'le
' to oter macros, suc as 4o"volve0T, =eco"volve0T,
' =eco"volve-t, a"d 8a'or.
' -:35T6
' Te first colum" must co"tai" te varia'le (e.%., time,
' or freque"cy), te seco"d colum" te real com&o"e"ts of
' te i"&ut data, te tird colum" teir ima%i"ary com+
' &o"e"ts. 0or &urely real i"&ut data, eiter leave te
' tird colum" 'la"1, or fill it wit 7eros. Li1ewise, for
' &urely ima%i"ary i"&ut data, te seco"d colum" sould
' o"ly co"tai" 7eros, 'la"1s, or com'i"atio"s tereof.
' Te macro acce&ts two i"&ut formats6 (1) data wit time
' or freque"cy values ce"tered arou"d 7ero (,#i%" N +1),
' a"d (2) data wit time or freque"cy values starti"% at
' 7ero (,#i%" N 1). Te out&ut format is comme"surate wit
' te i"&ut format used.
' 25T35T6
' Te out&ut is writte" i" te tree colum"s to te ri%t
' of te i"&ut data 'loc1, tere'y overwriti"% a"y &rior
' data i" tat re%io". Te out&ut colum"s co"tai" (from
' left to ri%t) freque"cy or time, te real com&o"e"ts
' of te out&ut data, a"d teir ima%i"ary com&o"e"ts.
' 3R24(=5R(6
' To i"itiate te tra"sform, i%li%t te tree colum"s
' of te i"&ut array, a"d call o"e of te two macros,
' 0orward0T() or -"verse0T().
' (M>M3L(#6
' 5ses of tis macro are illustrated i" ca&ters H a"d A
' of >dva"ced ()cel, starti"% wit sectio" H.1.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& For3ardFT()
=im i#i%" >s -"te%er
i#i%" N 1
4all 0ourier(i#i%")
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& In%erseFT()
=im i#i%" >s -"te%er
i#i%" N +1
4all 0ourier(i#i%")
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Fourier(i#i%")
' 4ec1 te array le"%t ", wic must 'e a &ower of 2,
' a"d 'e at least 2
=im c: >s -"te%er, c"Ma) >s -"te%er, ,#i%" >s -"te%er
=im : >s Lo"%, :: >s Lo"%
=im r: >s Lo"%, r"Ma) >s Lo"%
=im Le"%t >s #i"%le
=im 4ec11 >s =ou'le, 4ec12 >s =ou'le
=im =e"om >s =ou'le, -"terval >s =ou'le, Z >s =ou'le
=im =ata>rray >s Garia"t, 2ut&ut>rray >s Garia"t
=im myRa"%e >s Ra"%e
=im >"s, >"swer
!e%i"6
: N 0
r"Ma) N #electio".Rows.4ou"t
Le"%t N 4#"%(r"Ma))
c"Ma) N #electio".4olum"s.4ou"t
' -f area was "ot i%li%ted
-f r"Ma) N 1 >"d c"Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, P0ourier tra"sformatio"P)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
-f Le"%t R 2 Te"
Ms%!o) PTere must 'e at least two rows.P
("d
("d -f
=o $ile Le"%t I 1
Le"%t N Le"%t C 2
Loo&
-f Le"%t RI 1 Te"
Ms%!o) PTe curre"t "um'er of rows is P ? r"Ma) Q
? Pwic is "ot a" i"te%er &ower of two.P
("d
("d -f
' 4ec1 tat tere are tree i"&ut colum"s
-f c"Ma) RI B Te"
Ms%!o) PTere must 'e tree i"&ut colum"s,P Q
? 4r(1B) ? Po"e for te varia'le (time, freque"+,P Q
? 4r(1B) ? Pcy, etc.), te "e)t two for te realP Q
? 4r(1B) ? Pa"d ima%i"ary &arts of te i"&ut data.P
("d
("d -f
' Read te i"&ut data
=ata>rray N #electio".Galue
' 4ec1 tat te first colum" as its first two eleme"ts
4ec11 N GarTy&e(=ata>rray(1, 1))
-f 4ec11 N 0 Te"
Ms%!o) P("ter te to& left value.P
("d
("d -f
4ec12 N GarTy&e(=ata>rray(2, 1))
-f 4ec12 N 0 Te"
Ms%!o) P("ter a value i" row 2 of te first colum".P
("d
("d -f
' =etermi"e wat i"&ut co"ve"tio" is used6
' ,#i%" N +1 for i"&ut data ce"tered arou"d 7ero,
' ,#i%" N 1 for i"&ut data starti"% at 7ero
,#i%" N 0
-"terval N (=ata>rray(2, 1) + =ata>rray(1, 1)) * r"Ma)
-f =ata>rray(1, 1) I (+0.H * -"terval C r"Ma)) >"d Q
=ata>rray(1, 1) R (0.H * -"terval C r"Ma)) Te" ,#i%" N 1
-f =ata>rray(1, 1) R (+0.H * -"terval C r"Ma)) >"d Q
=ata>rray(r"Ma) C 2 J 1, 1) I (+0.H * -"terval C r"Ma)) Q
>"d =ata>rray(r"Ma) C 2 J 1, 1) R (0.H * -"terval C Q
r"Ma)) Te" ,#i%" N +1
-f ,#i%" N 0 Te"
Ms%!o) PTe i"&ut format is i"correct.P Q
? 4r(1B) ? P-t sould eiter 'e ce"teredP Q
? 4r(1B) ? Parou"d 7ero, or start at 7ero.P
("d
("d -f
' Read a"d rearra"%e te i"&ut data
:: N 2 * r"Ma)
Re=im Term(::) >s =ou'le
-f ,#i%" N 1 Te"
0or r: N 1 To r"Ma)
Term(2 * r: + 1) N =ata>rray(r:, 2)
Term(2 * r:) N =ata>rray(r:, B)
:e)t r:
("d -f
-f ,#i%" N +1 Te"
0or r: N 1 To r"Ma) C 2
Term(2 * r: + 1) N =ata>rray(r"Ma) C 2 J r:, 2)
Term(2 * r:) N =ata>rray(r"Ma) C 2 J r:, B)
Term(r"Ma) J 2 * r: + 1) N =ata>rray(r:, 2)
Term(r"Ma) J 2 * r:) N =ata>rray(r:, B)
:e)t r:
("d -f
' 4ec1 tat te out&ut does "ot overwrite valua'le data
#electio".2ffset(0, B).#elect
2ut&ut>rray N #electio".Galue
0or r: N 1 To r"Ma)
0or c: N 1 To c"Ma)
Z N 2ut&ut>rray(r:, c:)
-f (-s(m&ty(Z) 2r Z N 0) Te"
: N :
(lse
: N : J 1
("d -f
:e)t c:
:e)t r:
-f : I 0 Te"
>"s N Ms%!o)(P Tere are data i" te s&ace wereP Q
? 4r(1B) ? Pte out&ut will 'e writte". 3roceed P Q
? 4r(1B) ? P a"yway a"d overwrite tose dataOP, Q
v'Ees:o)
-f >"s N v':o Te"
#electio".2ffset(0, +B).#elect
("d
("d -f
("d -f
' 4alculate a"d write te freque"cy or time scale
-f ,#i%" N 1 Te"
0or r: N 1 To r"Ma) C 2
=ata>rray(r:, 1) N (r: + 1) C -"terval
:e)t r:
0or r: N (r"Ma) C 2 J 1) To r"Ma)
-f i#i%" I 0 Te"
=ata>rray(r:, 1) N (r: + r"Ma) + 1) C -"terval
(lse
=ata>rray(r:, 1) N (r: + 1) C -"terval
("d -f
:e)t r:
("d -f
-f ,#i%" N +1 Te"
0or r: N 1 To r"Ma)
=ata>rray(r:, 1) N (+(r"Ma) C 2) J r: + 1) C -"terval
:e)t r:
("d -f
' 4alculate te 0ourier tra"sform
4all 0T(Term, ::, i#i%")
' >rra"%e a"d write te out&ut data
=e"om N (r"Ma) J 1 J i#i%" * (r"Ma) + 1)) C 2
-f ,#i%" N 1 Te"
0or r: N 1 To r"Ma)
=ata>rray(r:, 2) N Term(2 * r: + 1) C =e"om
=ata>rray(r:, B) N Term(2 * r:) C =e"om
:e)t r:
("d -f
-f ,#i%" N +1 Te"
0or r: N 1 To r"Ma) C 2
=ata>rray(r:, 2) N Term(r"Ma) J 2 * r: + 1) C =e"om
=ata>rray(r:, B) N Term(r"Ma) J 2 * r:) C =e"om
=ata>rray((r"Ma) C 2) J r:, 2) N Q
Term(2 * r: + 1) C =e"om
=ata>rray((r"Ma) C 2) J r:, B) N Term(2 * r:) C =e"om
:e)t r:
("d -f
>&&licatio".#cree"5&dati"% N 0alse
#electio".Galue N =ata>rray
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& FT(Term, ::, i#i%")
' Te followi"% is te 0ourier tra"sform routi"e 025R1 from
' _. 4. #&rott, P:umerical Reci&es6 Routi"es a"d ()am&les
' i" !>#-4P, 4am'rid%e 5"iversity 3ress, 4o&yri%t (4)1@@1
' 'y :umerical Reci&es #oftware. 5sed ere 'y &ermissio".
' 5se of tis routi"e oter ta" as a" i"te%ral &art of te
' &rese"t 'oo1 requires a" additio"al lice"se from :umeri+
' cal Reci&es #oftware. 0urter distri'utio" is &roi'ited.
' Te routi"e as 'ee" modified to yield dou'le+&recisio"
' results, a"d to co"form to te sta"dard matematical si%"
' co"ve"tio" for 0ourier tra"sformatio".
=im i >s Lo"%, i#te& >s Lo"%, , >s Lo"%
=im m >s Lo"%, mMa) >s Lo"%
=im tr >s =ou'le, ti >s =ou'le, teta >s =ou'le
=im wtem& >s =ou'le, wi >s =ou'le, wr >s =ou'le
=im w&i >s =ou'le, w&r >s =ou'le
, N 1
0or i N 1 To :: #te& 2
-f , I i Te"
tr N Term(,)
ti N Term(, J 1)
Term(,) N Term(i)
Term(, J 1) N Term(i J 1)
Term(i) N tr
Term(i J 1) N ti
("d -f
m N -"t(:: C 2)
$ile m IN 2 >"d , I m
, N , + m
m N -"t(m C 2)
$e"d
, N , J m
:e)t i
mMa) N 2
$ile :: I mMa)
i#te& N 2 * mMa)
teta N 2 * >&&licatio".3i() C (+i#i%" * mMa))
w&r N +2 * #i"(0.H * teta) ; 2
w&i N #i"(teta)
wr N 1
wi N 0
0or m N 1 To mMa) #te& 2
0or i N m To :: #te& i#te&
, N i J mMa)
tr N wr * Term(,) + wi * Term(, J 1)
ti N wr * Term(, J 1) J wi * Term(,)
Term(,) N Term(i) + tr
Term(, J 1) N Term(i J 1) + ti
Term(i) N Term(i) J tr
Term(i J 1) N Term(i J 1) J ti
:e)t i
wtem& N wr
wr N wr * w&r + wi * w&i J wr
wi N wi * w&r J wtem& * w&i J wi
:e)t m
mMa) N i#te&
$e"d
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''*******************************''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''* "a&or Trans#ormation *''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''*******************************''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' 8a'or tra"sformatio" a"aly7es a time+de&e"de"t si%"al i"
' terms of its freque"cy co"te"t as a fu"ctio" of time. -t
' does tis 'y multi&lyi"% te time+de&e"de"t si%"al 'y a
' movi"% 8aussia" wi"dow, a"d 'y te" 0ourier+tra"sformi"%
' te resulti"% &roduct. Te result is stored i" two
' arrays, Re2ut() a"d -m2ut(), wic co"tai" te real a"d
' ima%i"ary &arts of te 0ourier tra"sform as a fu"ctio" of
' time a"d freque"cy. Te co"te"ts of o"e of tese arrays,
' or of te corres&o"di"% ma%"itude or &ase a"%le, ca"
' te" 'e dis&layed i" a color ma& (usi"% Ma&&er) or a B+=
' &lot.

' #5!R25T-:(#6
' Tis macro requires te su'routi"e 0T.
' -:35T6

' -" i"&ut i"formatio" sould 'e &laced i" two ad,ace"t
' colum"s, wit te left+most colum" co"tai"i"% time, te
' ri%t+most te corres&o"di"% si%"al. Te macro is re+
' stricted to equidista"t data, a"d te time i"creme"ts
' must terefore 'e equal. Te widt of te movi"% wi"dow
' must 'e a" odd &ower of 2 (ere set to 'e at least a
' factor 2 smaller ta" te "um'er of data i" te set),
' a"d is selected wit a" i"&ut 'o).
' 25T35T6
' Te result is dis&layed wit a time a)is o" to&, a"d a
' freque"cy a)is to te left, ready for immediate visuali+
' 7atio" wit Ma&&er.
' 3R24(=5R(6
' -" order to start te 8a'or tra"sform, call te macro
' a"d e"ter te requested i"formatio" i" te i"&ut 'o)es.
' $>R:-:86
' Tis macro &roduces a lar%e out&ut array to te ri%t of
' te i"&ut data. -t does :2T cec1 weter tat array
' co"tai"s a"y i"formatio" tat sould "ot 'e overwritte".
' Terefore ma1e sure tat tere is "o valua'le i"formatio"
' o" te s&readseet to te ri%t of te i"&ut colum"s.
' (M>M3L(6
' 5se of tis macro is illustrated i" sectio"s A.@ a"d A.10
' of >(B.
' data>rray i"&ut data set, two colum"s wide, te left+
' most for time, te ri%tmost for si%"al
' M te "um'er of data i" te set, i.e., te
' "um'er of rows i" data>rray
' : te "um'er of data used for te wi"dow,
' smaller ta" a'out alf of M
' 8aussia" te wi"dow fu"ctio" used, co"tai"i"% : &oi"ts
' Re2ut te real com&o"e"t of te out&ut si%"al,
' as a fu"ctio" of time a"d freque"cy
' -m2ut te ima%i"ary com&o"e"t of te out&ut si%"al,
' as a fu"ctio" of time a"d freque"cy
' Ma%2ut te ma%"itude (a'solute value) of te out&ut
' si%"al, as a fu"ctio" of time a"d freque"cy
' Lo%2ut te 10+'ased lo%aritm of te ma%"itude of
' te out&ut si%"al, as a fu"ctio" of time
' a"d freque"cy
' 3ase2ut te &ase a"%le (i" radia"s) of te out&ut
' si%"al, as a fu"ctio" of time a"d freque"cy
Su& "a&or()
=im i >s -"te%er, , >s -"te%er, ,, >s -"te%er
=im m >s -"te%er, MM >s -"te%er, : >s -"te%er
=im :: >s -"te%er, Mi"#&aci"% >s -"te%er
=im 3 >s -"te%er, #&aci"% >s -"te%er
=im 8aussia"() >s =ou'le, -m2ut() >s =ou'le
=im -"terval >s =ou'le, Lo%2ut() >s =ou'le
=im Ma%2ut() >s =ou'le, :orm >s =ou'le
=im 3ase2ut() >s =ou'le, 3i >s =ou'le, Re2ut() >s =ou'le
=im s >s =ou'le, Term() >s =ou'le
=im =ata>rray >s Garia"t, freq>rray >s Garia"t
=im 2ut&ut>rray >s Garia"t
=im myRa"%e >s Ra"%e
=im Messa%e1, Messa%eB, Title1, TitleB, =efaultB
' Read te time i"terval
Messa%e1 N PTe time i"terval 'etwee" successive data is6P
Title1 N P8a'or -"&ut!o) 16 Time i"tervalP
-"terval N -"&ut!o)(Messa%e1, Title1)
' Read te i"&ut data
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i" colum"6P, Title6N Q
P8a'or -"&ut!o) 26 -"&ut dataP, Ty&e6NK)
myRa"%e.#elect
' 4ec1 tat tere is o"ly o"e data i"&ut colum"
-f #electio".4olum"s.4ou"t RI 1 Te"
Ms%!o) PTere ca" o"ly 'e 2:( data i"&ut colum".P
("d
("d -f
=ata>rray N #electio".Galue
freq>rray N #electio".Galue
2ut&ut>rray N #electio".Galue
m N #electio".Rows.4ou"t
' =etermi"e te si7e of te wi"dow widt :
MM N m C 9
: N 2
=o
: N 2 * :
Loo& 5"til : I MM
' #et te mi"imum sam&le s&aci"%
Mi"#&aci"% N -"t((m + : J 1) C 12H)
,, N Mi"#&aci"%
' #elect a sam&le s&aci"%
Messa%eB N PTe mi"imum sam&le s&aci"% is6P
TitleB N P8a'or -"&ut!o) B6 #am&le s&aci"%P
=efaultB N Mi"#&aci"%
#&aci"% N -"&ut!o)(Messa%eB, TitleB, =efaultB)
-f #&aci"% IN Mi"#&aci"% Te" ,, N #&aci"%
' 4om&ute te freque"cy scale
0or i N 1 To :
freq>rray(i, 1) N P P
:e)t i
0or i N 1 J : C 2 To :
freq>rray(i, 1) N (+: J 2 * i + 2) C (2 * : * -"terval)
:e)t i
0or i N : J 1 To : J 1
freq>rray(i, 1) N (+: J 2 * i + 2) C (2 * : * -"terval)
:e)t i
' =is&lay te freque"cy scale
#electio".2ffset(0, 1).#elect
#electio".Galue N freq>rray
>&&licatio".#cree"5&dati"% N 0alse
' 4om&ute te wi"dow fu"ctio" 8aussia"()
Re=im 8aussia"(1 To :)
3i N X3i()Y
s N : C A
:orm N 12 C #qr(2 * 3i)
0or i N 1 To :
8aussia"(i) N Q
:orm * ()&(+(i + (: J 1) C 2) ; 2 C (2 * s * s))
:e)t i
' Te mai" loo&, re&eati"% te a"alysis M+:J1 times
0or , N ,, To m + : J 1 #te& ,,
' $i"dow te i"&ut data fra%me"t a"d rearra"%e it for 00T
:: N 2 * :
Re=im Term(::) >s =ou'le
0or i N 1 To :
Term(2 * i + 1) N =ata>rray(i J , + 1, 1) * 8aussia"(i)
Term(2 * i) N 0
:e)t i
' 4all te forward 0ourier tra"sform su'routi"e
4all 0T(Term, ::, 1)
' 4om&ute te out&ut data. Te followi"% sectio" &rese"ts
' several out&ut o&tio"s, of wic o"ly o"e com'i"atio" ca"
' 'e selected at a"y o"e time. 0or %e"eral visuali7atio" of
' te result, Ma%2ut is usually te &referred out&ut format
Re=im Ma%2ut(:, m + : J 1)
' Re=im Re2ut(:, M + : J 1)
' Re=im -m2ut(:, M + : J 1)
' Re=im Lo%Ma%2ut(:, M + : J 1)
' Re=im 3ase2ut(:, M + : J 1)
0or i N 1 To :
Ma%2ut(i, ,) N Q
(#qr(Term(2 * i + 1) ; 2 J Term(2 * i) ; 2)) C :
' Re2ut(i, ,) N Term(2 * i + 1) C :
' -m2ut(i, ,) N Term(2 * i) C :
' Lo%Ma%2ut(i, ,) N 0.H * Lo%((Term(2 * i + 1) ; 2 Q
J Term(2 * i) ; 2) C :)
' 3ase2ut(i, ,) N >t"(Term(2 * i) C Term(2 * i + 1))
:e)t i
3 N -"t(100 * (, C (m + : J 1)))
>&&licatio".#tatus!ar N P4alculatio" P ? 3 ? P[ do"eP
' =ata out&ut
' (sow" ere for Ma%2ut< modify 'y re&laci"% Ma%2ut
' 'y alter"ative out&ut file "ame MMM(i, ,) if so desired)
0or i N 1 To : C 2 + 1
2ut&ut>rray(i, 1) N P P
:e)t i

0or i N : C 2 To : C 2
2ut&ut>rray(i, 1) N ,
:e)t i
0or i N 1 J : C 2 To :
2ut&ut>rray(i, 1) N Ma%2ut(i, ,)
:e)t i
0or i N : J 1 To : J 2
2ut&ut>rray(i, 1) N Ma%2ut(1, ,)
:e)t i
0or i N : J 2 To m
2ut&ut>rray(i, 1) N P P
:e)t i
#electio".2ffset(0, 1).#elect
#electio".Galue N 2ut&ut>rray
:e)t ,
>&&licatio".#tatus!ar N 0alse
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''*********************************'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''* "ram$Sc'midt *'''''''''''''
'''''''''''''* ort'ogonali)ation *'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''*********************************'''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tis su'routi"e uses 8ram+#cmidt orto%o"ali7atio" to
' com&ute a"d dis&lay te orto%o"al &oly"omials corres&o"+
' di"% to o"e or more i"de&e"de"t varia'les ), wic "eed
' "ot 'e equidista"t. -t also &rovides te fitti"% &ara+
' meters, teir sta"dard deviatio"s, a"d teir ratios.
' Te latter are co"ve"ie"t for determi"i"% wic terms
' are statistically si%"ifica"t a"d sould 'e retai"ed.
' #5!R25T-:(#6
' Tis macro requires te su'routi"es Multi&ly, -"vert,
' a"d Tra"s&ose
' -:35T6
' Te i"&ut data must 'e arra"%ed as follows. Te first
' colum" must co"tai" te de&e"de"t varia'le y. Te seco"d
' (a"d su'seque"t) colum"(s) must co"tai" te i"de&e"de"t
' varia'le(s) ).
' Te su'routi"e requires a" i"&ut &arameter &6 & N 1
' causes a %e"eral u"wei%ted least squares fit to te
' data, wile & N 0 forces te fit to &ass trou% te
' ori%i", i.e., it assumes tat E N 0 for M N 0. Te su'+
' routi"e 2rto is terefore called 'y a macro, 2rtoI or
' 2rtoO, tat sets te value of &.
' 25T35T6
' Te macro &roduces its out&ut to te ri%t of te i"&ut,
' se&arated 'y o"e em&ty colum". -t terefore re&eats te
' y colum". -t te" com&utes te fitti"% &arameters a"d
' teir sta"dard deviatio"s. #i"ce tese are u"correlated,
' a covaria"ce matri) is "eiter "eeded "or &rovided. Te
' sta"dard deviatio" of te fit is sow" directly 'elow te
' la'el P4oeff6P, as i" L#- a"d L#2. > tird row lists te
' ratio of te a'solute values of te coefficie"t a"d te
' corres&o"di"% sta"dard deviatio".
' -" %e"eral you will :2T wa"t to use te listed coeffi+
' cie"ts a"d sta"dard deviatio"s, wic a&&ly to te orto+
' %o"ali7ed i"de&e"de"t &arameters. Te most useful &art of
' te out&ut is te row listi"% teir ratios, wic i"di+
' cates wic orders sould 'e co"sidered (%ree" if ratio I
' H) a"d wic sould "ot 'e (red if ratio R 1).
' 3R24(=5R(6
' !efore calli"% te macro, ma1e sure tat te out&ut area
' (a 'loc1 to te ri%t of te i"&ut data 'loc1, 'ut e)te"+
' di"% o"e more colum" a"d tree more rows) co"tai"s "o
' valua'le data, si"ce tese will 'e overwritte".
' -" order to start te &rocess, i%li%t te e"tire i"&ut
' data array, i.e., te recta"%ular 'loc1 co"tai"i"% te
' colum" for y a"d te ad,ace"t colum"(s) for te corres+
' &o"di"% values of ), te" call eiter 2rto(1) or
' 2rto(0)
' Te fu"ctio" of te followi"% two drivers is merely to
' set te value of o"e &arameter, &, equal to eiter o"e or
' 7ero, i" order to coose 'etwee" a %e"eral least squares
' fitti"% (& N 1) or o"e tat forces te curve trou% te
' ori%i" (& N 0).
' (M>M3L(#6
' 5se of tis macro is illustrated starti"% i" sectio"s
' B.11 trou% B.19 of >(B.
Su& Ort'oO() ' for u"wei%ted L# fit trou% te ori%i"

=im 3 >s =ou'le
3 N 0
4all 2rto(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Ort'oI() ' for %e"eral u"wei%ted least squares fit

=im 3 >s =ou'le
3 N 1
4all 2rto(3)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Ort'o(3)
=im 4Ma) >s -"te%er, c: >s -"te%er, , >s -"te%er
=im MM >s -"te%er, : >s -"te%er
=im i >s Lo"%, m >s Lo"%, RMa) >s Lo"%
=im :um >s =ou'le, Resid >s =ou'le
=im Root >s =ou'le, ##R >s =ou'le, #t=ev0 >s =ou'le
=im #f >s =ou'le, #EZ >s =ou'le, #ZZ >s =ou'le
=im u >s =ou'le, varE >s =ou'le
=im '>rray >s Garia"t, coeff>rray >s Garia"t
=im =ata>rray >s Garia"t, =e"om >s Garia"t
=im lcc>rray >s Garia"t, orto>rray >s Garia"t
=im 2ut&ut>rray >s Garia"t, stdev>rray >s Garia"t
=im v>rray >s Garia"t, v0>rray >s Garia"t
=im M>rray >s Garia"t, E>rray >s Garia"t
=im Z >s Garia"t
=im myRa"%e >s Ra"%e
=im >"swer, >"swer, i>"swer, 1>"swer
' =etermi"atio" of te array si7e6
!e%i"6
RMa) N #electio".Rows.4ou"t
4Ma) N #electio".4olum"s.4ou"t
Re=im a(0 To 4Ma)) >s =ou'le, s(0 To 4Ma)) >s =ou'le
u N 1
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, P2rtoP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 tat te "um'er of colum"s is at least 26
-f 4Ma) R 2 Te"
Ms%!o) PTere must 'e at least two colum"s,P ? Q
4r(1B) ? Po"e for E, a"d o"e or more for M.P, Q
, P2rto%o"ali7atio"P
("d
("d -f
' 4ec1 tat rma) I cma), so tat te "um'er of data
' &oi"ts is sufficie"t to defi"e te &ro'lem6
-f RMa) R 4Ma) Te"
Ms%!o) PTere must 'e at least P ? 4Ma) ? P i"&utP ? Q
4r(1B) ? P data to defi"e te &ro'lem.P, Q
, P2rto%o"ali7atio"P
("d
("d -f

' =ime"sio" te arrays6
Re=im '>rray(1 To 4Ma)) >s =ou'le
Re=im =e"om(1 To 4Ma))
Re=im v>rray(1 To 4Ma), 1 To 4Ma)) >s =ou'le
Re=im M>rray(1 To RMa), 1 To 4Ma)) >s =ou'le
Re=im E>rray(1 To RMa)) >s =ou'le
Re=im Z(1 To RMa), 1 To 4Ma)) >s =ou'le
' Read te data>rray, te" fill y>rray a"d )>rray.
=ata>rray N #electio".Galue
0or i N 1 To RMa)
E>rray(i) N =ata>rray(i, 1)
:e)t i
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, 1)) Te"
Ms%!o) PE+value(s) missi"%P, , P2rto%o"ali7atio"P
("d
("d -f
:e)t i
0or , N 2 To 4Ma)
0or i N 1 To RMa)
-f -s(m&ty(=ata>rray(i, ,)) Te"
Ms%!o) PM+value(s) missi"%P, , P2rto%o"ali7atio"P
("d
("d -f
:e)t i
:e)t ,
' 0ill te first colum" of )>rray wit 7eroes
' (for & N 0) or o"es (for & N 1), te rest wit
' te data i" te )+colum"(s)
0or i N 1 To RMa)
M>rray(i, 1) N 4='l(3)
:e)t i
0or , N 2 To 4Ma)
0or i N 1 To RMa)
M>rray(i, ,) N =ata>rray(i, ,)
:e)t i
:e)t ,
c: N 1
' =ime"sio" a"d fill Z, te matri) of colum" vectors
' already tra"sformed, i"itially Z is te 1st colum" of
' )>rray if & N 1, te 2"d if & N 0
Re=im Z(1 To RMa), 1 To c:) >s =ou'le
' 4ec1 a%ai"st overwriti"% valua'le s&readseet
' data 'y te out&ut of orto%o"al &oly"omials
#electio".2ffset(0, 4Ma) J 1).#elect
orto>rray N #electio".Galue
2ut&ut>rray N #electio".Galue
m N 0
0or i N 1 To RMa)
0or , N 1 To 4Ma)
-f -s(m&ty(2ut&ut>rray(i, ,)) Te"
m N m
(lse
m N m J 1
("d -f
:e)t ,
:e)t i
-f m I 0 Te"
>"swer N Ms%!o)(PTere are data i" te i%li%ted P Q
? Pout&ut 'loc1 to teP ? 4r(1B) ? Q
Pri%t of te i"&ut data array. 4a" tey 'e P Q
? Poverwritte"O P, v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te"
("d
("d -f
("d -f
' 4ec1 a%ai"st overwriti"% valua'le s&readseet data
' 'y te out&ut of coefficie"ts a"d sta"dard deviatio"s
#electio".2ffset(9, 0).#elect
2ut&ut>rray N #electio".Galue
MM N 0
0or i N RMa) + 1 To RMa)
0or , N 1 To 4Ma)
-f -s(m&ty(2ut&ut>rray(i, ,)) Te"
MM N MM
(lse
MM N MM J 1
("d -f
:e)t ,
:e)t i
-f MM I 0 Te"
>"swer N Ms%!o)(PTere are data i" te two 'ottom P Q
? Pli"es of te P ? 4r(1B) ? Pi%li%ted array. P Q
? P4a" tey 'e overwritte"O P, v'Ees:o, P2verwriteOP)
-f >"swer N v':o Te"
("d
("d -f
("d -f
#electio".2ffset(+9, 0).#elect
0or i N 1 To RMa)
orto>rray(i, 1) N =ata>rray(i, 1)
:e)t i
>&&licatio".#cree"5&dati"% N 0alse
=o
0or i N 1 To RMa)
0or , N 1 To c:
Z(i, c:) N M>rray(i, ,)
:e)t ,
:e)t i
' =ime"sio" a"d fill Zi, te "e)t colum" vector to 'e
' tra"sformed
Re=im Zi(1 To RMa), 1 To 1) >s =ou'le
0or i N 1 To RMa)
Zi(i, 1) N M>rray(i, c: J 1)
:e)t i
' =ime"sio" te oter vectors a"d matrices
Re=im Zt&(1 To c:, 1 To RMa)) >s =ou'le ' N Z'
Re=im Zt&Z(1 To c:, 1 To c:) >s =ou'le ' N Z' Z
Re=im Z1(1 To c:, 1 To c:) >s =ou'le ' N (Z' Z)P
Re=im Zt&Zi(1 To c:, 1 To 1) >s =ou'le ' N Z' Zi
Re=im Z2(1 To c:, 1 To 1) >s =ou'le
' N Z1 Zt&Zi N (Z' Z)P Z' Zi
Re=im ZB(1 To RMa), 1 To 1) >s =ou'le
' N Z Z2 N Z (Z' Z)P Z' Zi
' 4om&ute Z1 N (Z' Z)P
4all Tra"s&ose(Z, RMa), c:, Zt&)
4all Multi&ly(Zt&, c:, RMa), Z, c:, Zt&Z)
4all -"vert(Zt&Z, c:, Z1)
4all Multi&ly(Zt&, c:, RMa), Zi, 1, Zt&Zi)
4all Multi&ly(Z1, c:, c:, Zt&Zi, 1, Z2)
4all Multi&ly(Z, RMa), c:, Z2, 1, ZB)
' =ime"sio" a"d com&ute Ztf N Zi + ZB, te tra"sformed
' vector, orto%o"al to te vector(s) i" Z
Re=im Ztf(1 To RMa), 1 To 1) >s =ou'le
' N Zi + Z (Z' Z)P (Z' Zi)
0or i N 1 To RMa)
Ztf(i, 1) N Zi(i, 1) + ZB(i, 1)
:e)t i
#EZ N 0
#ZZ N 0
0or i N 1 To RMa)
#EZ N #EZ J E>rray(i) * Ztf(i, 1)
#ZZ N #ZZ J Ztf(i, 1) * Ztf(i, 1)
orto>rray(i, c: J 1) N Ztf(i, 1)
:e)t i
-f c: R 4Ma) Te" c: N c: J 1
Re=im 3reserve Z(1 To RMa), 1 To c:) >s =ou'le
Loo& 5"til c: N 4Ma)
' =is&lay te orto%o"al array
#electio".Galue N orto>rray
' 5&date y>rray a"d )>rray.
0or i N 1 To RMa)
E>rray(i) N orto>rray(i, 1)
:e)t i
0or i N 1 To RMa)
M>rray(i, 1) N 4='l(3)
:e)t i
0or , N 2 To 4Ma)
0or i N 1 To RMa)
M>rray(i, ,) N orto>rray(i, ,)
:e)t i
:e)t ,
' 4om&ute te coefficie"ts
0or , N 2 + 3 To 4Ma)
:um N 0
=e"om(,) N 0
0or i N 1 To RMa)
:um N :um J M>rray(i, ,) * E>rray(i)
=e"om(,) N =e"om(,) J M>rray(i, ,) * M>rray(i, ,)
:e)t i
'>rray(,) N :um C =e"om(,)
:e)t ,
' 4om&ute te varia"ce of y
##R N 0
0or i N 1 To RMa)
Resid N E>rray(i)
0or , N 2 + 3 To 4Ma)
Resid N Resid + '>rray(,) * M>rray(i, ,)
:e)t ,
##R N ##R J Resid * Resid
:e)t i
varE N ##R C (RMa) + 4Ma) + 3 J 1)
#t=ev0 N #qr(>'s(varE))
' 4om&ute te varia"ces of te coefficie"ts
0or , N 2 + 3 To 4Ma)
v>rray(,, ,) N varE C =e"om(,)
:e)t ,
>ctive4ell.2ffset(RMa), 0).#elect
' >rra"%e for te data out&ut
0or , N 1 To 4Ma)
$it >ctive4ell.0o"t
.!old N True
.-talic N True
.4olor-"de) N 1
("d $it
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
0or , N 1 To 4Ma)
>ctive4ell.0o"t.-talic N True
>ctive4ell.0o"t.4olor-"de) N 1
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
0or , N 1 To 4Ma)
>ctive4ell.0o"t.-talic N True
>ctive4ell.0o"t.4olor-"de) N 1
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(+2, +4Ma) + 3).#elect
$it >ctive4ell
.0o"t.!old N True
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N P4oeff6P
("d $it
>ctive4ell.2ffset(0, 1).#elect
0or , N 2 + 3 To 4Ma)
$it >ctive4ell.0o"t
.!old N True
.-talic N True
.4olor-"de) N 1
("d $it
>ctive4ell.Galue N '>rray(,)
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma) + 3).#elect
$it >ctive4ell.0o"t
.!old N 0alse
.-talic N True
.4olor-"de) N 1
("d $it
>ctive4ell.Dori7o"tal>li%"me"t N )lRi%t
>ctive4ell.Galue N P#t=ev6P
>ctive4ell.2ffset(0, 1).#elect
>ctive4ell.0o"t.4olor-"de) N 1
0or , N 2 + 3 To 4Ma)
-f v>rray(,, ,) R 1(+90 Te"
>ctive4ell.Galue N PR1(+20P
(lse
>ctive4ell.Galue N #qr(>'s(v>rray(,, ,)))
("d -f
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma) + 3).#elect
$it >ctive4ell
.0o"t.!old N 0alse
.0o"t.-talic N True
.0o"t.4olor-"de) N 1
.Dori7o"tal>li%"me"t N )lRi%t
.Galue N PRatio6P
("d $it
>ctive4ell.2ffset(0, 1).#elect
0or , N 2 + 3 To 4Ma)
-f v>rray(,, ,) RN 0 Te"
>ctive4ell.Galue N P:C>P
>ctive4ell.0o"t.4olor-"de) N 1
("d -f
-f v>rray(,, ,) I 0 Te"
>ctive4ell.0o"t.!old N 0alse
>ctive4ell.0o"t.-talic N True
>ctive4ell.0o"t.4olor-"de) N 1A
>ctive4ell.Galue N >'s('>rray(,) Q
C #qr(v>rray(,, ,)))
-f >ctive4ell.Galue I H Te" Q
>ctive4ell.0o"t.4olor-"de) N 10
-f >ctive4ell.Galue R 1 Te" Q
>ctive4ell.0o"t.4olor-"de) N B
("d -f
>ctive4ell.2ffset(0, 1).#elect
:e)t ,
>ctive4ell.2ffset(1, +4Ma)).#elect
' 3rovide te sta"dard deviatio" of te fit
>ctive4ell.2ffset(0, 1 + 3).#elect
$it >ctive4ell.0o"t
.!old N 0alse
.-talic N True
.4olor-"de) N 1
("d $it
#electio".Galue N #t=ev0
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''***********************************''''''''''''
''''''''''''* *''''''''''''
''''''''''''* (irect 8(e9Con%olution *''''''''''''
''''''''''''* *''''''''''''
''''''''''''***********************************''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tese macros &erform a strai%tforward (i.e., "o"+0ourier
' tra"sform) co"volutio" or deco"volutio" of 2 colum"s of
' real data, arra"%ed i" a si"%le 'loc1 of B ad,ace"t
' colum"s, te first colum" co"tai"i"% te varia'le (time),
' te seco"d colum" te si%"als to 'e co"volved, a"d te
' tird colum" te tra"sfer fu"ctio". Te si%"al i" te
' tird colum" is "ormali7ed to ave a" avera%e of 1.
' Te "um'er of &oi"ts i" te data set is ar'itrary, 'ut
' te data must 'e equidista"t, si"ce te si%"al a"d tra"s+
' fer fu"ctio"s will 'e slidi"% &ast eac oter.
' 4o"volutio" te"ds to s&read te fu"ctio". Ma1e sure tat
' tere is e"ou% s&ace for it to s&read i"to, e.%., 'y ad+
' di"% 7eros 'efore a"dCor after te si%"al for e)&a"sio".
' Li1ewise, for a symmetrical tra"sfer fu"ctio", si%"al
' sifti"% ca" 'e &reve"ted 'y ce"teri"% te tra"sfer
' fu"ctio" at t N 0.
' Te deco"volutio" routi"e wor1s well we" te deco"vol+
' vi"% fu"ctio" (i" te tird colum") is a mo"oto"ically
' decreasi"% fu"ctio" of time, 'ut oterwise may lead to
' oscillatio"s.
' #5!R25T-:(#6
' Te macros 4o"volve a"d =eco"volve set te value of d
' to J1 (for co"volutio") or +1 (for deco"volutio"), te"
' call te su'routi"e 4o"volutio". Te latter requires "o
' furter su'routi"es.
' -:35T6
' Te macro acce&ts a"y "um'er of i"&ut data, 'ut requires
' tat tey 'e equidista"t. Te out&ut is i"de&e"de"t of
' te starti"% value of te time scale, 'ut does de&e"d o"
' te &ase relatio"si& 'etwee" te two i"&ut si%"als.
' 25T35T6
' Te out&ut is writte" i" o"e colum", immediately to te
' ri%t of te i"&ut data 'loc1, tere'y overwriti"% a"y
' &rior data i" tat re%io". >fter writi"% te out&ut, te
' activated area retur"s to its ori%i"al &ositio" a"d
' co"te"ts.
' 3R24(=5R(6
' !efore starti"% te macro, ma1e sure tat te colum" to
' te ri%t of te i"&ut data 'loc1 co"tai"s "o valua'le
' data.
' To i"itiate te tra"sform, i%li%t te tree colum"s of
' te i"&ut array, a"d call te macro.
' (M>M3L(6
' 5se of tis macro is illustrated i" sectio"s A.2 a"d A.B
' of >dva"ced ()cel.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Con%ol%e()
=im = >s -"te%er
= N 1
4all 4o"volutio"(=)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& (econ%ol%e()
=im = >s -"te%er
= N +1
4all 4o"volutio"(=)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Con%olution(=)
=im 4Ma) >s -"te%er, rM >s -"te%er, RMa) >s -"te%er
=im i >s -"te%er, , >s -"te%er, : >s -"te%er
=im -"cr >s =ou'le, my#um >s =ou'le
=im #um >s =ou'le, Z >s =ou'le
=im -"& >s Garia"t, my-"&ut >s Garia"t
=im my-"&ut2 >s Garia"t, my2ut&ut >s Garia"t
=im 2ut& >s Garia"t, Tra"s >s Garia"t
=im >"s, >"swer
' Read te i"&ut
!e%i"6
4Ma) N #electio".4olum"s.4ou"t
RMa) N #electio".Rows.4ou"t
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, P(=e)4o"volutio"P)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 tat tere are tree i"&ut colum"s
-f 4Ma) RI B Te"
Ms%!o) PTere must 'e tree i"&ut colum"s,P Q
? 4r(1B) ? Po"e eac for time, si%"al s, a"dP Q
? 4r(1B) ? Ptra"sfer fu"ctio" t, i" tat order.P
("d
("d -f
' Read te i"&ut data
my-"&ut N #electio".Galue
my-"&ut2 N #electio".0ormula
-"cr N my-"&ut(2, 1) + my-"&ut(1, 1)
rM N RMa) + 1
Re=im -"&(+rM To rM)
Re=im 2ut&(+rM To rM)
Re=im Tra"s(+rM To rM)
' 4ec1 weter te fourt colum" ca" 'e overwritte"
: N 0
#electio".2ffset(0, 1).#elect
my2ut&ut N #electio".Galue
0or i N 1 To RMa)
Z N my2ut&ut(i, B)
-f (-s(m&ty(Z) 2r Z N 0) Te"
: N :
(lse
: N : J 1
("d -f
:e)t i
-f : I 0 Te"
>"s N Ms%!o)(PTere are data i" te s&ace wereP Q
? 4r(1B) ? Pte out&ut will 'e writte". 3roceedP Q
? 4r(1B) ? Pa"yway a"d overwrite tose dataOP, v'Ees:o)
-f >"s N v':o Te"
#electio".2ffset(0, +1).#elect
("d
("d -f
("d -f
#electio".2ffset(0, +1).#elect
' :ormali7e a"d i"vert te tra"sfer fu"ctio"
#um N 0
0or i N 1 To RMa)
#um N #um J my-"&ut(i, B)
:e)t i
0or i N 1 To RMa)
-"&(1 + i) N 0
-"&(i + 1) N my-"&ut(i, 2)
Tra"s(i + 1) N 0
Tra"s(1 + i) N my-"&ut(i, B)
2ut&(1 + i) N 0
2ut&(i + 1) N 0
:e)t i
' 4om&ute te co"volutio" (for d N 1)
-f = N 1 Te"
0or , N 0 To rM
my#um N 0
0or i N 0 To rM
my#um N my#um J -"&(, + i) * Tra"s(+i)
:e)t i
2ut&(,) N my#um C #um
my2ut&ut(, J 1, B) N 2ut&(,)
:e)t ,
("d -f
' 4om&ute te deco"volutio" (for d N +1)
-f = N +1 Te"
0or , N 0 To rM
my#um N -"&(,)
0or i N 1 To rM
my#um N my#um + 2ut&(, + i) * Tra"s(+i)
:e)t i
2ut&(,) N my#um
:e)t ,
0or , N 1 To RMa)
my2ut&ut(,, B) N 2ut&(, + 1) * #um
:e)t ,
("d -f
' 2ut&ut te result
#electio".2ffset(0, 1).#elect
#electio".Galue N my2ut&ut
#electio".2ffset(0, +1).#elect
#electio".0ormula N my-"&ut2
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''*********************************************'''''''
'''''''* *'''''''
'''''''* Fourier Trans#orm 8(e9Con%olution *'''''''
'''''''* *'''''''
'''''''*********************************************'''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tese macros &erform eiter a co"volutio" or a deco"volu+
' tio" of two sets of real data, arra"%ed i" a si"%le 'loc1
' of tree ad,ace"t colum"s, te first colum" co"tai"i"%
' teir commo" varia'le (e.%., time), a"d te "e)t colum"s
' te data sets to 'e co"volved or deco"volved.
' 0or co"volutio" te order of te seco"d a"d tird colum"
' does "ot matter, a"d i"terca"%i"% te data sets i" te
' seco"d a"d tird colum" will yield te same result.
' 0or deco"volutio", te seco"d colum" sould co"tai" te
' data to 'e deco"volved, a"d te tird colum" te data set
' wit wic te data i" te seco"d colum" are to 'e deco"+
' volved. -" tis case, e)ca"%i"% te seco"d a"d tird
' colum" will i" %e"eral yield quite differe"t results.
' 0or deco"volutio" te macro i"cor&orates a" ad,usta'le
' vo" Da"" wi"dow wit a si"%le, co"ti"ually ad,usta'le
' &ositive &arameter, w. Te default, w N 0, yields a
' recta"%ular wi"dow (i.e., te a'se"ce of filteri"%), 'ut
' allows te user to select a sar& i%+freque"cy cut+off.
' #etti"% w N 1 selects te traditio"al vo" Da"" wi"dow,
' wile oter w+values I0 &roduce filteri"% tat is less
' severe (0 R w R 1) or more severe (w I 1) ta" te sta"+
' dard vo" Da"" filter. :ote tat te filters ave "ot 'ee"
' "ormali7ed.
' #5!R25T-:(#6
' Te macros 4o"volve a"d =eco"volve require te su'routi"e
' 4o"volutio" wic, i" tur", calls te su'routi"e 0T.
' -:35T6
' Te macro acce&ts a"y i"&ut format i" wic te time
' scale co"tai"s 2;" equidista"t values (were " is a &osi+
' tive i"te%er lar%er ta" 1), re%ardless of its starti"%
' value. $ile te out&ut is i"de&e"de"t of te starti"%
' value of te time scale, it does de&e"d o" te &ase
' relatio"si& 'etwee" te two i"&ut si%"als.
' 3rovided tat te fu"ctio" i" te tird colum" is symme+
' trical, suc &ase sifts ca" 'e avoided 'y starti"% tat
' fu"ctio" at its &oi"t of symmetry (ty&ically6 at its
' ma)imum), a"d &laci"% te &art 'efore tat &oi"t of
' symmetry at te very e"d of te colum". $at ma1es tis
' 'wra&+arou"d' metod wor1 is te assum&tio" of te
' 0ourier tra"sform metod tat te fu"ctio"s are self+
' re&eati"%.
' 25T35T6
' Te out&ut is writte" i" o"e colum", immediately to te
' ri%t of te i"&ut data 'loc1, tere'y overwriti"% a"y
' &rior data i" tat re%io". >fter writi"% te out&ut,
' te activated area retur"s to its ori%i"al &ositio" a"d
' co"te"ts.
' 3R24(=5R(6
' !efore starti"% te macro, ma1e sure tat te colum" to
' te ri%t of te i"&ut data 'loc1 co"tai"s "o valua'le
' data.
' To i"itiate te tra"sform, i%li%t te tree colum"s
' of te i"&ut array, a"d call te macro.
' (M>M3L(6
' 5se of tis macro is illustrated i" sectio" A.H of >(B.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Te followi"% are te two drivers for te (de)co"volutio"
' su'routi"e. Tey set 1#i%" to eiter J1 (for co"volutio")
' or +1 (for deco"volutio").
Su& Con%ol%eFT()
=im 1#i%" >s -"te%er
1#i%" N 1
4all 4o"volutio"0T(1#i%")
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& (econ%ol%eFT()
=im 1#i%" >s -"te%er
1#i%" N +1
4all 4o"volutio"0T(1#i%")
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Con%olutionFT(1#i%")
=im c: >s -"te%er, c"Ma) >s -"te%er
=im : >s -"te%er, :: >s -"te%er, "fZ >s -"te%er
=im r: >s -"te%er, r"Ma) >s -"te%er, rr" >s -"te%er
=im "fZero >s #i"%le, S >s #i"%le
=im >vera%eB >s =ou'le, 4ec11 >s =ou'le, 4ec12 >s =ou'le
=im = >s =ou'le, data#&aci"% >s =ou'le, Le"%t >s =ou'le
=im Mi" >s =ou'le, :orm >s =ou'le, 3i >s =ou'le
=im Ratio >s =ou'le, R"m2 >s =ou'le, s >s =ou'le
=im #um >s =ou'le, #umB >s =ou'le
=im $i"dow0u"ctio" >s =ou'le, Z >s =ou'le
=im =ata>rray >s Garia"t, -"&ut>rray >s Garia"t
=im 2ut&ut>rray >s Garia"t
=im >"swer, >"swer, v>"swer, =efault1, =efault2
=im Messa%e1, Messa%e2, Title1, Title2
' Read te i"&ut
!e%i"6
: N 0
Z N 0
r"Ma) N #electio".Rows.4ou"t
:: N 2 * r"Ma)
c"Ma) N #electio".4olum"s.4ou"t
Le"%t N 4='l(r"Ma))
' -f area was "ot i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, P0ourier tra"sform (de)co"volutio"P)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
' 4ec1 te array le"%t ", wic must 'e a &ower of 2,
' a"d 'e at least 2
-f Le"%t R 2 Te"
Ms%!o) PTere must 'e at least two rows.P
("d
("d -f
=o $ile Le"%t I 1
Le"%t N Le"%t C 2
Loo&
-f Le"%t RI 1 Te"
Ms%!o) PTe "um'er of rows must 'e a &ower of two.P
("d
("d -f
' 4ec1 tat tere are tree i"&ut colum"s
c"Ma) N #electio".4olum"s.4ou"t
-f c"Ma) RI B Te"
-f 1#i%" N 1 Te"
Ms%!o) P Tere must 'e B i"&ut colum"s,P Q
? 4r(1B) ? Po"e for te i"de&e"de"t varia'leP Q
? 4r(1B) ? P (e.%., time), te "e)t for teP Q
? 4r(1B) ? P two fu"ctio"s to 'e co"volved.P
("d
("d -f
-f 1#i%" N +1 Te"
Ms%!o) P Tere must 'e B i"&ut colum"s,P Q
? 4r(1B) ? Po"e for te i"de&e"de"t varia'leP Q
? 4r(1B) ? P (e.%., time), te "e)t for teP Q
? 4r(1B) ? P two fu"ctio"s to 'e deco"volved.P
("d
("d -f
("d -f
' Read te i"&ut data
=ata>rray N #electio".Galue
-"&ut>rray N #electio".0ormula
' 4ec1 tat te first colum" as its first two eleme"ts
4ec11 N GarTy&e(=ata>rray(1, 1))
-f 4ec11 N 0 Te"
Ms%!o) P("ter te to& left value.P
("d
("d -f
4ec12 N GarTy&e(=ata>rray(2, 1))
-f 4ec12 N 0 Te"
Ms%!o) P("ter a value i" row 2 of te first colum".P
("d
("d -f
data#&aci"% N =ata>rray(2, 1) + =ata>rray(1, 1)
' Read a"d rearra"%e te i"&ut data
' from te seco"d a"d tird colum"s
Re=im Term2(::) >s =ou'le, TermB(::) >s =ou'le
Re=im Term9(::) >s =ou'le
0or r: N 1 To r"Ma)
Term2(2 * r: + 1) N =ata>rray(r:, 2)
Term2(2 * r:) N Z
TermB(2 * r: + 1) N =ata>rray(r:, B)
TermB(2 * r:) N Z
:e)t r:
' :ormali7e te data i" te tird colum"
#um N 0
0or r: N 1 To r"Ma)
#um N #um J TermB(2 * r: + 1)
:e)t r:
0or r: N 1 To r"Ma)
' -f "ormali7atio" is :2T desired,
' comme"t out te "e)t li"e6
TermB(2 * r: + 1) N TermB(2 * r: + 1) * r"Ma) C #um
:e)t r:
' 4ec1 tat te out&ut does "ot overwrite valua'le data.
#electio".2ffset(0, 1).#elect
2ut&ut>rray N #electio".Galue
0or r: N 1 To r"Ma)
S N 2ut&ut>rray(r:, B)
-f (-s(m&ty(S) 2r S N 0) Te"
: N :
(lse
: N : J 1
("d -f
:e)t r:
#electio".2ffset(0, +1).#elect
-f : I 0 Te"
>"swer N Ms%!o)(P Tere are data i" te colum" wereP Q
? 4r(1B) ? Pte out&ut will 'e writte". 3roceedP ? Q
4r(1B) ? P a"yway a"d overwrite tose dataOP, v'Ees:o)
-f >"swer N v':o Te" ("d
("d -f
' Tra"sform te data from te seco"d a"d tird colum"s
4all 0T(Term2, ::, 1)
4all 0T(TermB, ::, 1)
' Multi&ly i" te freque"cy domai" for co"volutio", or
' divide i" te freque"cy domai" for deco"volutio". 0or
' deco"volutio", a mi"imum value Pmi"P (ar'itrarily set
' ere to 1(+A) &reve"ts divisio" 'y 7ero. Moreover, a"
' i"&ut 'o) is &rovided for o&tio"al "oise filteri"%.
R"m2 N 4='l(r"Ma)) * 4='l(r"Ma))
' 0or co"volutio", multi&ly i" te freque"cy domai"6
' (a J ,') (c J ,d) N (ac + 'd) J ,(ad J 'c)
-f 1#i%" N 1 Te"
0or r: N 1 To r"Ma)
Term9(2 * r: + 1) N Q
(Term2(2 * r: + 1) * TermB(2 * r: + 1) Q
+ Term2(2 * r:) * TermB(2 * r:)) C r"Ma)
Term9(2 * r:) N Q
(Term2(2 * r: + 1) * TermB(2 * r:) Q
J Term2(2 * r:) * TermB(2 * r: + 1)) C r"Ma)
:e)t r:
("d -f
' 0or deco"volutio", select te wi"dow &arameter s
-f 1#i%" N +1 Te"

Mi" N 0.000001
3i N X3i()Y
Messa%e1 N P("ter te wi"dow &arameter, a P ? Q
P"o"+"e%ative "um'er.P ? 4r(1B) ? PTe default P ? Q
Pis 0, wic corres&o"ds to "o filteri"%,P ? 4r(1B) ? Q
P'ut allows you to i"sert a sar& freque"cy cut+off.P Q
? 4r(1B) ? 4r(1B) ? P0or te sta"dard vo" Da"" P Q
? Pfilter select 1.P ? 4r(1B) ? 4r(1B) Q
? P0or a" ad,usta'le vo" Da"" C Tu1ey wi"dow,P Q
? 4r(1B) ? P select a value oter ta" 0 or 1.P
Title1 N P>d,usta'le vo" Da"" C Tu1ey wi"dowP
=efault1 N P0P
s N -"&ut!o)(Messa%e1, Title1, =efault1)
-f s R Mi" Te" s N 0
' 3rovide te o&tio" of removi"%
' i%+freque"cy data for M1 N 0
-f s N 0 Te"
Messa%e2 N P("ter te "um'er of freque"ciesP Q
? 4r(1B) ? P(a" i"te%er smaller ta" P Q
? r"Ma) ? P) for wicP ? 4r(1B) Q
? Pyou wa"t te si%"al to 'e set to 7ero.P ? Q
4r(1B) ? 4r(1B) ? P3ress (:T(R or 2L for te P Q
? Pdefault, 0,P ? 4r(1B) ? Pi" wic case "o P Q
? Pdata will 'e set to 7ero.P
Title2 N PZeroi"% out i% freque"ciesP
=efault2 N P0P
"fZero N -"&ut!o)(Messa%e2, Title2, =efault2)
-f "fZero R 0 Te" "fZ N 0
-f "fZero I 0 >"d "fZero R r"Ma) C 2 Te" Q
"fZ N 4-"t("fZero)
-f "fZero I r"Ma) C 2 Te" "fZ N r"Ma) C 2
-f "fZ I 0 Te"
0or r: N (r"Ma) C 2 J 2 + "fZ) To (r"Ma) C 2 J "fZ)
Term9(2 * r: + 1) N 0
Term9(2 * r: + 2) N 0
:e)t r:
("d -f
("d -f

' 0or deco"volutio", divide i" te freque"cy domai"6
' (aJ,')C(cJ,d) N (aJ,')(c+,d)C(ccJdd)
' N X(acJ'd)J,('c+ad)YC(ccJdd)

0or r: N 1 To r"Ma)
= N (TermB(2 * r: + 1) * TermB(2 * r: + 1) J Q
TermB(2 * r:) * TermB(2 * r:)) * data#&aci"% C r"Ma)
-f = R Mi" Te" = N Mi"
Term9(2 * r: + 1) N Q
(Term2(2 * r: + 1) * TermB(2 * r: + 1) Q
J Term2(2 * r:) * TermB(2 * r:)) C =
Term9(2 * r:) N (Term2(2 * r:) * TermB(2 * r: + 1) Q
+ Term2(2 * r: + 1) * TermB(2 * r:)) C =

' 4om&ute a"d a&&ly te wi"dow fu"ctio"

Ratio N 2 * 4='l(r: + 1) C 4='l(r"Ma))
-f s R 1 Te" $i"dow0u"ctio" N 1
-f s I 0 >"d s R 1 Te"
-f >'s(Ratio + 1) R s Te" $i"dow0u"ctio" N Q
0.H J 0.H * 4os(3i * (>'s(Ratio) + 1 J s) C s)
("d -f
-f s IN 1 Te"
$i"dow0u"ctio" N (0.H J 0.H * 4os(3i * Ratio)) ; s
("d -f
Term9(2 * r: + 1) N Term9(2 * r: + 1) * $i"dow0u"ctio"
Term9(2 * r:) N Term9(2 * r:) * $i"dow0u"ctio"
:e)t r:
("d -f
' 4alculate out&ut data
4all 0T(Term9, ::, +1)
' >rra"%e a"d write te out&ut data
0or r: N 1 To r"Ma)
2ut&ut>rray(r:, B) N Term9(2 * r: + 1) C r"Ma)
:e)t r:
>&&licatio".#cree"5&dati"% N 0alse
#electio".2ffset(0, 1).#elect
#electio".Galue N 2ut&ut>rray
#electio".2ffset(0, +1).#elect
#electio".Galue N -"&ut>rray
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''************************************''''''''''''
'''''''''''* *''''''''''''
'''''''''''* Iterati%e (econ%olution *''''''''''''
'''''''''''* *''''''''''''
'''''''''''************************************''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tis macro &erforms a" iterative deco"volutio" alo"% te
' li"es of te va" 4ittert a&&roac. -t co"volves (rater
' ta" deco"volves) te data i" te seco"d (si%"al) colum"
' wit te filter fu"ctio" i" te tird colum", te"
' corrects te si%"al 'y te differe"ce 'etwee" it a"d its
' co"volutio". Te macro &rovides te o&tio" of smooti"%
' i"termediate results wit a movi"% quadratic of selec+
' ta'le le"%t, usi"% te recursive e)&ressio"s %ive" 'y
' 8orry i" >"al. 4em. A2 (1@@0) H*0. Te iteratio" sto&s
' we" te sum of te squares of te residuals as reaced
' a mi"imum, or te "um'er of iteratio"s as reaced a &re+
' set limit.
' Tere are two coices6 =eco"volve-t0 i"volves "o
' co"strai"ts, wile =eco"volve-t1 assumes o"e co"strai"t,
' "amely tat te fu"ctio" is always &ositive. -t terefore
' re&laces all "e%ative i"termediate results 'y 7ero.
' -:35T6
' Te i"&ut requires tree ad,ace"t colum"s of equal
' le"%t. Te first colum" sould co"tai" te i"de&e"de"t
' &arameter, suc as time, wavele"%t, etc. Te seco"d
' colum" sould co"tai" te (real) i"&ut data tat "eed to
' 'e deco"volved wit te (real) filter data i" te tird
' colum".
' Te macro acce&ts a"y "um'er of i"&ut data, 'ut requires
' tat tey 'e equidista"t. Te out&ut is i"de&e"de"t of
' te starti"% value of te time scale, 'ut does de&e"d o"
' te &ase relatio"si& 'etwee" te two i"&ut si%"als.
' >" o&tio"al &ara'olic "oise filter is &rovided to reduce
' te effect of "oise. 5se of suc a filter i"troduces its
' ow" distortio", te more so te lo"%er te le"%t of te
' movi"% &ara'ola. -f used at all, te &ara'ola le"%t
' sould terefore 'e 1e&t to a mi"imum.
' -:T(RR53T6
' !ecause te iteratio" ca" ta1e more time ta" you may
' ave availa'le or care to s&e"d, te &rocess ca" 'e
' i"terru&ted, 'y &ressi"% eiter te (sca&e 1ey or te
' 4o"trolJ!rea1 1ey com'i"atio". > messa%e 'o) te"
' &rovides te o&tio" of e"di"% te com&utatio" a"d
' dis&layi"% te result o'tai"ed so far, or of resumi"%
' te calculatio" were it was i"terru&ted.
' 25T35T6
' Te out&ut is writte" i" o"e colum", immediately to te
' ri%t of te i"&ut data 'loc1, tere'y overwriti"% a"y
' &rior data i" tat re%io". >fter writi"% te out&ut,
' te activated area retur"s to its ori%i"al &ositio" a"d
' co"te"ts. Moreover, te "um'er of iteratio"s used, a"d
' te value of te termi"atio" criterio" are sow" at te
' 'ottom of te data set.
' #5!R25T-:(# >:= 05:4T-2:#6
' Te macros =eco"v-t0 a"d =eco"volve-t1 require te
' su'routi"e =eco"volve-teratively wic, i" tur", calls
' te su'routi"e 0T. Moreover, we" filteri"% is used,
' te fu"ctio"s 4o"volutio"$ei%t, 8ram3oly"omial, a"d
' 8e"0act are also required.
' 3R24(=5R(6
' !efore starti"% te macro, ma1e sure tat te colum" to
' te ri%t of te i"&ut data 'loc1 co"tai"s "o valua'le
' data.
' To i"itiate te macro, i%li%t te tree colum"s of te
' i"&ut array, a"d call te macro. Te macro will te" as1
' you to s&ecify te ma)imum "um'er of iteratio"s< its
' default value is 10, a"d its ma)imum value as 'ee" set
' at 100,000. (-f tat ta1es you too lo"%, i"terru&t te
' iteratio"s wit (sc.) Te iteratio"s will sto& we"ever
' te sum of te squares of te residuals as reaced a
' mi"imum, or te set ma)imum "um'er of iteratio"s as 'ee"
' &erformed, wicever comes first.
' (M>M3L(6
' 5se of tis macro is illustrated i" sectio" A.A of >(B.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 0or iterative deco"volutio" witout co"strai"ts6
Su& (econ%ol%eIt:()
=im 77 >s -"te%er
77 N 0
4all =eco"volve-teratively(77)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 0or iterative deco"volutio" co"strai"ed at ) N 06
Su& (econ%ol%eIt*()
=im 77 >s -"te%er
77 N 1
4all =eco"volve-teratively(77)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& (econ%ol%eIterati%ely(77)
=im 4 >s -"te%er, c: >s -"te%er, c"Ma) >s -"te%er
=im -t:o >s -"te%er, : >s -"te%er
=im :: >s -"te%er, "fZ >s -"te%er
=im r: >s -"te%er, r"Ma) >s -"te%er, rr" >s -"te%er
=im "fZero >s #i"%le, S >s #i"%le
=im >vera%eB >s =ou'le, 4ec11 >s =ou'le, 4ec12 >s =ou'le
=im = >s =ou'le, data#&aci"% >s =ou'le, =elta >s =ou'le
=im 0actor >s =ou'le, Le"%t >s =ou'le, Ma)-t:o >s =ou'le
=im Mi" >s =ou'le, my#cale >s =ou'le, :orm >s =ou'le
=im 3 >s =ou'le, 3i >s =ou'le, &revious##R >s =ou'le
=im Ratio >s =ou'le, R"m2 >s =ou'le, ##R >s =ou'le
=im s >s =ou'le, #um >s =ou'le
=im #umB >s =ou'le, $i"dow0u"ctio" >s =ou'le, Z >s =ou'le
=im =ata>rray >s Garia"t, -"&ut>rray >s Garia"t
=im 2ut&ut>rray >s Garia"t
=im a>, '', cc, >"swer, >"swer, v>"swer, 4o"ti"ueDere
=im =efault, -"terru&tDa"dler, Messa%e, my0ilter
=im my0u"ctio", Re&ly, Title, Try>%ai"
' Read te i"&ut
!e%i"6
: N 0
Z N 0
r"Ma) N #electio".Rows.4ou"t
:: N 2 * r"Ma)
c"Ma) N #electio".4olum"s.4ou"t
Le"%t N 4='l(r"Ma))
3i N X3i()Y
' -f area was "ot i%li%ted
-f r"Ma) N 1 >"d c"Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, P-terative (de)co"volutio"P)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
2" (rror 8oTo -"terru&tDa"dler
' 4ec1 te array le"%t ", wic must
' 'e a &ower of 2, a"d 'e at least 2
-f Le"%t R 2 Te"
Ms%!o) PTere must 'e at least two rows.P
("d
("d -f
=o $ile Le"%t I 1
Le"%t N Le"%t C 2
Loo&
-f Le"%t RI 1 Te"
Ms%!o) PTe "um'er of rows must 'e a &ower of two.P
("d
("d -f
' 4ec1 tat tere are tree i"&ut colum"s
-f c"Ma) RI B Te"
Ms%!o) PTere must 'e tree i"&ut colum"s, o"e for P Q
? PteP ? 4r(1B) ? P i"de&e"de"t varia'le (e.%., P Q
? Ptime), te "e)tP ? 4r(1B) Q
? P two for te two fu"ctio"s to 'e deco"volved.P
("d
("d -f
' Read te i"&ut data
=ata>rray N #electio".Galue
-"&ut>rray N #electio".0ormula
' 4ec1 tat te first colum" as its first two eleme"ts
4ec11 N GarTy&e(=ata>rray(1, 1))
-f 4ec11 N 0 Te"
Ms%!o) P("ter te to& left value.P
("d
("d -f
4ec12 N GarTy&e(=ata>rray(2, 1))
-f 4ec12 N 0 Te"
Ms%!o) P("ter a value i" row 2 of te first colum".P
("d
("d -f
data#&aci"% N =ata>rray(2, 1) + =ata>rray(1, 1)
' 4ec1 tat te out&ut does "ot overwrite valua'le data.
#electio".2ffset(0, 1).#elect
2ut&ut>rray N #electio".Galue
0or r: N 1 To r"Ma)
S N 2ut&ut>rray(r:, B)
-f (-s(m&ty(S) 2r S N 0) Te"
: N :
(lse
: N : J 1
("d -f
:e)t r:
#electio".2ffset(0, +1).#elect
-f : I 0 Te"
>"swer N Ms%!o)(PTere are data i" te colum" wereP ? Q
4r(1B) ? Pte out&ut will 'e writte". 3roceedP ? Q
4r(1B) ? P a"yway a"d overwrite tose dataOP, v'Ees:o)
-f >"swer N v':o Te" ("d
("d -f
' #elect a filter
Try>%ai"6
Messa%e N PEou ca" select a movi"% &ara'ola to filterP ? Q
4r(1B) ? Pte data. #&ecify a movi"% &ara'ola wit a"P ? Q
4r(1B) ? Podd i"te%er "um'er of data &oi"ts, at leastP ? Q
4r(1B) ? PH 'ut always muc smaller ta" te "um'erP ? Q
4r(1B) ? Pof &oi"ts i" your data set, or select teP ? Q
4r(1B) ? Pdefault, 0, if you do :2T wa"t a"y filteri"%.P
Title N P=eco"volve -teratively6 #elect movi"% &oly"omial le"%tP
=efault N P0P
my0ilter N -"&ut!o)(Messa%e, Title, =efault)
-f my0ilter N 0 Te" 8oTo a>
m N 4-"t((my0ilter + 1) C 2)
-f (m RI 0 >"d m R 2) Te"
Ms%!o) P#elect eiter 0 (for "o filteri"%),P ? Q
4r(1B) ? Por a" odd "um'er lar%er ta" B forP ? Q
4r(1B) ? Pte le"%t of te movi"% &ara'ola.P
8oTo Try>%ai"
("d -f
-f r"Ma) R 2 * m J B Te"
Ms%!o) P#elect a sorter movi"% &ara'ola le"%t.P
8oTo Try>%ai"
("d -f
a>6
' #ave te i"&ut si%"al
Re=im si%"al(1 To r"Ma)) >s =ou'le
Re=im "ew#i%"al(1 To r"Ma)) >s =ou'le
0or r: N 1 To r"Ma)
si%"al(r:) N =ata>rray(r:, 2)
:e)t r:
' Read a"d rearra"%e te i"&ut data from te tird colum"
Re=im TermB(1 To ::) >s =ou'le
0or r: N 1 To r"Ma)
TermB(2 * r: + 1) N =ata>rray(r:, B)
TermB(2 * r:) N Z
:e)t r:
' :ormali7e te data i" te tird colum"
#um N 0
0or r: N 1 To r"Ma)
#um N #um J =ata>rray(r:, B)
:e)t r:
my#cale N r"Ma) C #um
' #elect te ma)imum "um'er of iteratio"s< te
' default value is 10, a"d its ma)imum value is
' limited at 10000 to &reve"t a" e"dless loo&.
Messa%e N P#elect te ma)imum "um'er of iteratio"sP
Title N Q
P=eco"volve -teratively6 #elect ma). ] of iteratio"sP
=efault N P10P
Ma)-t:o N -"&ut!o)(Messa%e, Title, =efault)
-f Ma)-t:o I 10000 Te" Ma)-t:o N 10000
' Ma1e code u"i"terru&ti'le for "e)t sectio"
>&&licatio".("a'le4a"celLey N )l=isa'led
' #et te iteratio" "um'er a"d start te iteratio" loo&
-t:o N 1
''6
&revious##R N ##R
' Read a"d rearra"%e te i"&ut data from te seco"d colum"
Re=im Term2(::) >s =ou'le, Term9(::) >s =ou'le
0or r: N 1 To r"Ma)
Term2(2 * r: + 1) N =ata>rray(r:, 2)
Term2(2 * r:) N Z
TermB(2 * r: + 1) N =ata>rray(r:, B) * my#cale
TermB(2 * r:) N Z
:e)t r:
' Tra"sform te data from te seco"d a"d tird colum"s
4all 0T(Term2, ::, 1)
4all 0T(TermB, ::, 1)
' Multi&ly i" te freque"cy domai" for co"volutio"
R"m2 N 4='l(r"Ma)) * 4='l(r"Ma))
' Multi&ly i" te freque"cy domai", usi"%
' (a J ,') * (c J ,d) N (ac + 'd) J ,(ad J 'c)
' were , is te square root of +1
0or r: N 1 To r"Ma)
Term9(2 * r: + 1) N Q
(Term2(2 * r: + 1) * TermB(2 * r: + 1) Q
+ Term2(2 * r:) * TermB(2 * r:)) C r"Ma)
Term9(2 * r:) N (Term2(2 * r: + 1) * TermB(2 * r:) Q
J Term2(2 * r:) * TermB(2 * r: + 1)) C r"Ma)
:e)t r:
' -"verse tra"sform to o'tai" te co"volutio"
4all 0T(Term9, ::, +1)
0or r: N 1 To r"Ma)
2ut&ut>rray(r:, B) N Term9(2 * r: + 1) C r"Ma)
:e)t r:
' 4om&ute te corrected si%"al value
-f 77 R 2 Te"
0or r: N 1 To r"Ma)
3 N 1
-f 77 N 1 >"d si%"al(r:) R 0 Te" 3 N 0
"ew#i%"al(r:) N 3 * si%"al(r:) J Q
=ata>rray(r:, 2) + 2ut&ut>rray(r:, B)
:e)t r:
(lse-f 77 N 2 Te"
0or r: N 1 To r"Ma)
"ew#i%"al(r:) N si%"al(r:) J (1 + 2 * Q
>'s(si%"al(r:) + 0.H)) * (=ata>rray(r:, 2) + Q
2ut&ut>rray(r:, B))
:e)t r:
("d -f
' 4om&ute ##R
##R N 0
0or r: N 1 To r"Ma)
##R N ##R J (2ut&ut>rray(r:, B) + si%"al(r:)) ; 2
:e)t r:
-f my0ilter N 0 Te" 8oTo cc
' >&&ly te filter
Re=im #mooted>rray(r"Ma)) >s =ou'le
0or r: N 1 To r"Ma)
#mooted>rray(r:) N =ata>rray(r:, 2)
:e)t r:
1 N 2 ' for a &ara'ola
s N 0 ' for smooti"%
0or r: N 1 To m
#mooted>rray(r:) N 0
0or i N +m To m
#mooted>rray(r:) N #mooted>rray(r:) Q
J 4o"volutio"$ei%t(i, r: + m + 1, m, 1, s) Q
* =ata>rray(i J m J 1, 2)
:e)t i
:e)t r:
0or r: N m J 1 To r"Ma) + m
#mooted>rray(r:) N 0
0or i N +m To m
#mooted>rray(r:) N #mooted>rray(r:) Q
J 4o"volutio"$ei%t(i, 0, m, 1, s) Q
* =ata>rray(r: J i, 2)
:e)t i
:e)t r:
0or r: N r"Ma) + m J 1 To r"Ma)
#mooted>rray(r:) N 0
0or i N +m To m
#mooted>rray(r:) N #mooted>rray(r:) Q
J 4o"volutio"$ei%t(i, r: + r"Ma) J m, m, 1, s) Q
* =ata>rray(r"Ma) + m J i, 2)
:e)t i
:e)t r:
0or r: N 1 To r"Ma)
=ata>rray(r:, 2) N #mooted>rray(r:)
:e)t r:
cc6
' #et "e%ative values equal to 7ero for =eco"volve-t1
-f 77 N 1 Te"
0or r: N 1 To r"Ma)
-f =ata>rray(r:, 2) R 0 Te" =ata>rray(r:, 2) Q
N +=ata>rray(r:, 2)
:e)t r:
("d -f
4o"ti"ueDere6
' Ma1e code 'riefly i"terru&ti'le
>&&licatio".("a'le4a"celLey N )l(rrorDa"dler
' 5&date te seco"d (si%"al) colum" of data>rray
0or r: N 1 To r"Ma)
=ata>rray(r:, 2) N si%"al(r:) Q
J =ata>rray(r:, 2) + 2ut&ut>rray(r:, B)
:e)t r:
' i"creme"t -t:o a"d loo& 'ac1
-f -t:o N 1 Te" &revious##R N ##R
-t:o N -t:o J 1
>&&licatio".#tatus!ar N P-teratio" ] P ? Q
-t:o ? P, ##R N P ? ##R
-f (-t:o R Ma)-t:o >"d &revious##R IN ##R) Te" 8oTo ''
2ut&ut6
' 3re&are for la"di"%
0or r: N 1 To r"Ma)
2ut&ut>rray(r:, B) N si%"al(r:) Q
J =ata>rray(r:, 2) + 2ut&ut>rray(r:, B)
:e)t r:
-f 77 I 0 Te"
0or r: N 1 To r"Ma)
-f 2ut&ut>rray(r:, B) R 0 Te" Q
2ut&ut>rray(r:, B) N 0
:e)t r:
("d -f
' #ummari7e te &arameters used
' -f you do "ot wa"t a remi"der of te &arameters cose",
' a"d a dis&lay of te fi"al score o" te status 'ar, &lace
' te a&ostro&e 'efore te word Ms%!o)
Ms%!o) PTe &ro%ram =eco"volve-tP ? 77 ? P,P ? Q
4r(1B) ? Pusi"% a P ? my0ilter ? Q
P+&oi"t &ara'olic filter,P ? 4r(1B) ? Q
Pfou"d a" a"swer after P ? -t:o ? P iteratio"sP ? Q
4r(1B) ? Pwit a" ##R value of P ? ##R ? P.P
>&&licatio".#tatus!ar N 0alse
>&&licatio".#cree"5&dati"% N 0alse
#electio".2ffset(0, 1).#elect
#electio".Galue N 2ut&ut>rray
#electio".2ffset(0, +1).#elect
#electio".Galue N -"&ut>rray
("d
-"terru&tDa"dler6
-f (rr.:um'er N 1K Te"
Re&ly N Ms%!o)(P=o you wa"t to termi"ate teP ? Q
v'4r ? Pcom&utatio"O -f so, &ress EesP, v'Ees:o, Q
P=eco"volve-t6 #to& iteratio"OP)
-f Re&ly N v'Ees Te" 8oTo 2ut&ut
-f Re&ly N v':o Te"
Resume 4o"ti"ueDere
("d -f
("d -f
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Con%olution!eig't(i, t, m, 1, s) >s =ou'le
=im D >s -"te%er
=im #um >s =ou'le
#um N 0
0or D N 0 To 1
#um N #um J (2 * D J 1) * (8e"0act(2 * m, D) Q
C 8e"0act(2 * m J D J 1, D J 1)) Q
* 8ram3oly"omial(i, m, D, 0) Q
* 8ram3oly"omial(t, m, D, s)
:e)t D
4o"volutio"$ei%t N #um
("d 0u"ctio"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function "ramPolynomial(i, m, 1, s) >s =ou'le
-f 1 I 0 Te"
8ram3oly"omial N ((9 * 1 + 2) C (1 * (2 * m + 1 J 1))) Q
* (i * 8ram3oly"omial(i, m, 1 + 1, s) Q
J s * 8ram3oly"omial(i, m, 1 + 1, s + 1)) Q
+ ((1 + 1) C 1) * ((2 * m J 1) C (2 * m + 1 J 1)) Q
* 8ram3oly"omial(i, m, 1 + 2, s)
(lse-f 1 N 0 >"d s N 0 Te"
8ram3oly"omial N 1
(lse
8ram3oly"omial N 0
("d -f
("d 0u"ctio"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''*************************************'''''''''''
'''''''''''* *'''''''''''
'''''''''''* Integrate *'''''''''''
'''''''''''* *'''''''''''
'''''''''''*************************************'''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Te four macros u"der tis title use tra&e7oidal i"te%ra+
' tio", or its Rom'er% refi"eme"t, to com&ute te defi"ite
' i"te%ral of a fu"ctio" 0()) of a si"%le varia'le ). Eou
' ca" let te macro read te fu"ctio" >5T2matically from
' te s&readseet (as lo"% as 0()) co"tai"s ) i" "o more
' ta" si) differe"t &laces), or you ca" #3(4-0E it i" te
' fu"ctio" (quatio"()), i" wic case ) ca" occur a"y "um+
' 'er of times i" te matematical e)&ressio". Tis leaves
' te coice 'etwee" co"ve"ie"ce a"d e)ecutio" s&eed to te
' user6 avi"% to s&ecify te equatio" is less co"ve"ie"t
' 'ut yields muc faster e)ecutio", a co"sideratio" tat
' may 'ecome im&orta"t we" com&licated equatio"s are i"te+
' %rated,a"dCor we" i% accuracy is required.
' Te macro starts wit 2 data &oi"ts, fi"ds a tird &oi"t
' alf+way 'etwee" tem, te" dou'les te "um'er of
' i"tervals 'y alvi"% teir widts, tere'y i"creasi"%
' te "um'er of data &oi"ts to 2;1J1, were 1 cou"ts
' successive iteratio"s. _ust cou"ti"% te "um'er of data
' &oi"ts limits te "um'er ofiteratio"s to B0, 'ecause
' 2;B0J1 e)ceeds te ra"%e of i"te%ers defi"ed >s Lo"%.
' Te macro allows te user to s&ecify te required "um'er
' of si%"ifica"t (i.e., accurate) decimals, as well as te
' ma)imum "um'er 1Ma) of iteratio"s allowed. :ote6 te
' macro will dis&lay its results i" te sta"dard ()cel
' format, re%ardless of te "um'er of si%"ifica"t di%its i"
' tat result. -t also dis&layes te accumulated time ta1e"
' 'y te calculatio" at tat sta%e.
' Te i"te%ratio" will sto& we" successive estimates of
' te i"te%ral a%ree to witi" te s&ecified accuracy
' (wic ty&ically yields a" accuracy i" sli%t e)cess
' over te s&ecified value), or we" te s&ecified "um'er
' of iteratio"s as 'ee" reaced.
' > cell comme"t will alert te user we" te desired
' accuracy is "ot reaced witi" te s&ecified "um'er of
' iteratio"s. -" tat case te user may wa"t to re&eat te
' i"te%ratio" after i"creasi"% te "um'er of iteratio"s
' a"dCor decreasi"% te s&ecified "um'er of si%"ifica"t
' di%its.
' #5!R25T-:(#6

' Tis macro does "ot require a"y su'routi"es

' -:35T6

' 3lace ) i" te first, left+most colum", a"d 0()) i"
' te seco"d, ri%t+most colum" of a i%li%ted, two+
' colum"s wide recta"%ular 'loc1 of i"&ut data. Te to&
' row of te )+colum" sould co"tai" te lower i"te%ratio"
' limit, ) N a, te 'ottom row its u&&er i"te%ratio" limit,
' ) N '. Li1ewise, te to& item i" te 0()) colum" sould
' 'e 0(a), its 'ottom item 0('). (-f te &ositio"s of a
' a"d ' are i"terca"%ed, te "e%ative of te i"te%ral
' is o'tai"ed.)
' Ma1e sure tat te two colum"s of te i"&ut data 'loc1,
' for u& to BB rows 'elow tat data 'loc1, do "ot co"tai"
' valua'le material, wic oterwise may 'e overwritte" 'y
' te out&ut.
' >&art from te first few data &oi"ts, wic are o'tai"ed
' 'y i"vasive com&uti"%, te >5T2 versio" of tis macro uses
' reco"structio" of te s&readseet equatio" to com&ute te
' values of te fu"ctio" 0()) for successive )+values. Te
' ty&ically muc faster #3(4-0E versio" i"stead uses te
' e)&ressio" for 0()) s&ecified i" te fu"ctio" (quatio"().
' $e" you use Tra&e7#3(4-0E or Rom'er%#3(4-0E,
' &lease M>L( #5R( TD>T TD( (S5>T-2: 05:4T-2:
' -:=((= 42:T>-:# TD( 42RR(4T (M3R(##-2:
' rater ta" a" e)&ressio" left i"
' tat fu"ctio" from earlier use
' Te macro i"cludes a timer, wic dis&lays te total
' ela&sed time (i" seco"ds, wit a resolutio" of 0.1 s)
' for all iteratio"s made so far. !eyo"d te first few
' iteratio"s, te i"te%ratio" time rou%ly dou'les for
' every u"it i"crease i" te "um'er of iteratio"s used.
' Te timer illustrates te trade+off 'etwee" accuracy
' a"d iteratio" time.
' 0or te com&utatio", te i"&ut data 'loc1 sould ave at
' least tree rows, 'ut ca" ave ma"y more, as lo"% as te
' first a"d last row co"tai" te lower a"d i%er i"te%ra+
' tio" limit res&ectively. Dowever, u"less you 1"ow te
' &ro&erties of your fu"ctio" 0()), you sould first &lot
' te fu"ctio" (usi"% ma"y more rows) to see weter it
' co"tai"s a"y i"determi"ate &oi"ts, disco"ti"uities,
' a"dCorsi"%ularities. 0or suc a &lot, tree &oi"ts
' o'viously would "ot suffice.
' 25T35T6
' Te macro will write its out&ut 'elow te i"&ut data
' 'loc1, i" two la'eled colum"s, usi"% u& to BB rows.
' Te macro does :2T cec1 weter te out&ut mi%t over+
' write valua'le data, so &lease ma1e sure to remove suc
' data 'efore i%li%ti"% te i"&ut data 'loc1 a"d
' calli"% te macro.
' 4D2-4(#6

' Te followi"% coices are &rovided6
' Tra&e7>uto tra&e7oidal i"te%ratio" usi"% te
' s&readseet e)&ressio" (slow)
' Tra&e7#&ecify tra&e7oidal i"te%ratio" usi"% te
' fu"ctio" (quatio"()) (fast)
' Rom'er%>uto Rom'er% i"te%ratio" usi"% te
' s&readseet e)&ressio" (slow)
' Rom'er%#&ecify Rom'er% i"te%ratio" usi"% te
' fu"ctio" (quatio"()) (fast)
' Rom'er% i"te%ratio" is usually co"sidera'ly faster ta"
' tra&e7oidal i"te%ratio", e)ce&t we" te various
' derivatives at 'ot e"d&oi"ts are te same.
' (M>M3L(6
' 5se of tis macro is illustrated i" sectio" @.9 of >(B.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Euation(M)
' 0or use wit i"te%ratio" routi"es tat require a
' fu"ctio" to #3(4-0E te equatio" to 'e i"te%rated.
' Te equatio" ca" ave o"ly o"e varia'le, ), wic
' ca" 'e i"vo1ed a"y "um'er of times i" te equatio".
' ("ter te formula i" G!> format, i.e., square root
' as #qr rater ta" #qrt, te"+'ased lo%aritm as
' Lo%())CLo%(10) rater ta" as Lo%()), etc.
' Dere are a few e)am&le e)&ressio"s6
' (quatio" N #qr(1 + ) ; 2)
' (quatio" N ()&() ; 2) * (rfc())
' (quatio" N 9 * ) ; B + B * ) ; 2 J 2 * ) + 1
(quatio" N ()&(+1 * M ; 2)
("d 0u"ctio"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Trape)Auto()
=im 3 >s -"te%er, R >s -"te%er
3 N 0
R N 0
4all -"te%rate(3, R)
("d #u'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Trape)Speci#y()
=im 3 >s -"te%er, R >s -"te%er
3 N 1
R N 0
4all -"te%rate(3, R)
("d #u'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Rom&ergAuto()
=im 3 >s -"te%er, R >s -"te%er
3 N 0
R N 1
4all -"te%rate(3, R)
("d #u'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Rom&ergSpeci#y()
=im 3 >s -"te%er, R >s -"te%er
3 N 1
R N 1
4all -"te%rate(3, R)
("d #u'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Integrate(3, R)
=im , >s -"te%er, ,, >s -"te%er, 1 >s -"te%er, 11 >s -"te%er
=im 1Ma) >s -"te%er, Le"0 >s -"te%er, Le"MM >s -"te%er
=im m >s -"te%er, mMa) >s -"te%er
=im 3os=ollar1 >s -"te%er, 3os=ollar2 >s -"te%er
=im 3osMi"0 >s -"te%er, RMa) >s -"te%er
=im 4Ma) >s Lo"%, i >s Lo"%, ii >s Lo"%, iMa) >s Lo"%
=im : >s Lo"%
=im D >s =ou'le, DD >s =ou'le, &(rel >s =ou'le
=im #um >s =ou'le, Term >s =ou'le, v> >s =ou'le
=im v0> >s =ou'le, v! >s =ou'le, v0! >s =ou'le
=im f0 >s Garia"t, f-" >s Garia"t, -"te%ral >s Garia"t
=im -"terval >s Garia"t, 2ut&ut>rray >s Garia"t
=im Rom >s Garia"t
=im v0 >s Garia"t, v-" >s Garia"t, vM >s Garia"t
=im 4olum"#tri"%M >s #tri"%
=im Left0(1 To 20) >s #tri"%, Left00 >s #tri"%
=im Ri%t0(1 To 20) >s #tri"%, Row#tri"%M >s #tri"%
=im M >s #tri"%, MM >s #tri"%
=im r%-" >s Ra"%e, r%M >s Ra"%e, r%0 >s Ra"%e
=im a0, a-", >"swer, aM, =, f>, f!
=im Time1, Time2
= N K
1 N 1
11 N 1
1Ma) N 1H
m N 1
RMa) N #electio".Rows.4ou"t
4Ma) N #electio".4olum"s.4ou"t
a-" N #electio".>ddress
' Ma1e sure tat te i"&ut area is i%li%ted
-f RMa) N 1 >"d 4Ma) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, PTra&e7oidal i"te%ratio"P)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et r%-" N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data 'loc1 is located i"6P, Ty&e6NK)
r%-".#elect
a-" N #electio".>ddress
("d -f
RMa) N #electio".Rows.4ou"t
4Ma) N #electio".4olum"s.4ou"t
("d -f
' 4ec1 te si7e of te i"&ut ra"%e
-f 4Ma) RI 2 Te"
Ms%!o) PTe data must 'e i" two colum"s,P ? 4r(1B) Q
? Pte first for ), te seco"d for 0()).P, Q
, P-"te%ratio"P
("d
("d -f
-f RMa) R B Te"
Ms%!o) PTe i"&ut 'loc1 must aveP ? 4r(1B) ? Q
Pat least 'e tree rows.P, , P-"te%ratio"P
("d
("d -f
= N -"&ut!o) Q
(3rom&t6NPTe desired "um'er of si%"ifica"tP Q
? 4r(1B) ? Pdecimals i" te i"te%ral is P, Q
Title6NP>ccuracyP, =efault6NA)
-f = I 19 Te" = N 19
1Ma) N -"&ut!o) Q
(3rom&t6NPTe ma)imum "um'er of iteratio"s is P, Q
Title6NP-teratio"sP, =efault6N1H)
-f 1Ma) I B0 Te" 1Ma) N B0 ' 1Ma) N B1 yields i"te%er
' overflow eve" tou% " is dime"sio"ed >s Lo"%
>&&licatio".#cree"5&dati"% N 0alse
Time1 N Timer ' tis will measure te time ta1e" 'y te
' al%oritm, e)cludi"% user data e"try time
Re=im 2ut&ut>rray(1 To 1Ma), 1 To 2)
Re=im -"te%ral(1 To 1Ma))
Re=im -"terval(1 To 1Ma))
Re=im Rom(1 To 1Ma), 1 To 1Ma))
-f 3 N 0 Te"
' Read te i"&ut
aM N #electio"(2, 1).>ddress
f0 N #electio"(2, 2).0ormula
' Reco"struct te equatio" 0()) of f0. 5se te address a"d
' formula i" te seco"d row of te i"&ut data 'loc1, to
' allow te ri%t+a"d cells i" te to& a"d 'ottom rows of
' tat i"&ut data 'loc1 to 'e modified i" te &rese"ce of
' i"determi"ate values at o"e or 'ot of tese limits.
3os=ollar1 N -"#tr(1, aM, PTP)
3os=ollar2 N -"#tr(2, aM, PTP)
4olum"#tri"%M N Mid(aM, 2, Q
3os=ollar2 + 3os=ollar1 + 1)
Row#tri"%M N Mid(aM, 3os=ollar2 J 1, K)
MM N 4olum"#tri"%M ? Row#tri"%M
Le"MM N Le"(MM)
Le"0 N Le"(f0)
3osMi"0 N -"#tr(1, f0, MM)
Left0(m) N Left(f0, 3osMi"0 + 1)
Ri%t0(m) N Ri%t(f0, Le"0 + 3osMi"0 + Le"MM J 1)
' 4ec1 weter Ri%t0(1) co"tai"s more terms MM
3osMi"0 N -"#tr(1, Ri%t0(1), MM)
' 4o"ti"ue &arsi"% if Ri%t0(m) still co"tai"s MM
=o
-f 3osMi"0 N 0 Te" ()it =o
Le"0 N Le"(Ri%t0(m))
3osMi"0 N -"#tr(1, Ri%t0(m), MM)
-f 3osMi"0 RN 0 Te" ()it =o
Left0(m J 1) N Left(Ri%t0(m), 3osMi"0 + 1)
Ri%t0(m J 1) N Ri%t(Ri%t0(m), Q
Le"0 + 3osMi"0 + Le"MM J 1)
m N m J 1
3osMi"0 N -"#tr(1, Ri%t0(m), MM)
Loo& 5"til 3osMi"0 RN 0
mMa) N m
-f mMa) I A Te"
Ms%!o) PTe varia'le ) a&&ears more ta"P ? Q
4r(10) ? Psi) times i" te e)&ressio" for 0()).P ? Q
4r(10) ? P#&ecify te e)&ressio" i" te fu"ctio"P Q
? 4r(10) ? P(quatio"(), a"d te" use Tra&e7#&ecify.P
("d
("d -f
("d -f
' Read some i"&ut data from te i"&ut ra"%e r%-". 0or
' co"ve"ie"ce, te first few data are o'tai"ed 'y
' i"vasive com&uti"%, wile causi"% "e%li%i'le delay.
f-" N #electio".0ormula ' #ave for restoratio"
f> N f-"(1, 2)
f! N f-"(RMa), 2)
v-" N #electio".Galue
v> N v-"(1, 1) ' >6 lower i"te%ratio" limit
v0> N v-"(1, 2)
v! N v-"(RMa), 1) ' !6 i%er i"te%ratio" limit
v0! N v-"(RMa), 2)
DD N v! + v> ' DD6 )+ra"%e of i"te%ratio"
' #elect te su'+ra"%es r%M a"d r%0
v-" N #electio".Galue
aM N #electio"(2, 1).>ddress
a0 N #electio"(2, 2).>ddress
#et r%M N Ra"%e(aM)
r%M.#elect
vM N #electio".Galue ' Te value )
#et r%0 N Ra"%e(a0)
r%0.#elect
v0 N #electio".Galue ' Te value of 0())
f0 N #electio".0ormula ' Te formula 0())
' =etermi"e te i"te%ratio" limits
#um N v0> J v0!
, N 1
: N 2 ; , + 1
D N DD C (2 ; ,)
' 0irst cycle
0or i N 1 To : #te& 11
vM N v> J D * i
r%M.#elect
#electio".Galue N vM
r%0.#elect
v0 N #electio".Galue
#um N #um J 2 * v0
-"te%ral(1) N #um * D C 2
:e)t i
2ut&ut>rray(1, 1) N -"te%ral(1)
Time2 N Timer
-"terval(1) N Rou"d(Time2 + Time1, 1)
2ut&ut>rray(1, 2) N -"terval(1)
' #u'seque"t cycles
0or , N 1 J 1 To 1Ma)
: N 2 ; , + 1
D N DD C (2 ; ,)
0or i N 1 To : #te& 2 * 11
vM N v> J D * i

' -"terru&t te summatio" to reco"struct or read 0())

-f 3 N 0 Te"
-f mMa) N 1 Te" v0 N >&&licatio".(valuate Q
(Left0(1) ? #tr(vM) ? Ri%t0(1))
-f mMa) N 2 Te" v0 N >&&licatio".(valuate Q
(Left0(1) ? #tr(vM) ? Left0(2) ? #tr(vM) ? Ri%t0(2))
-f mMa) N B Te" v0 N >&&licatio".(valuate Q
(Left0(1) ? #tr(vM) ? Left0(2) ? #tr(vM) ? Q
Left0(B) ? #tr(vM) ? Ri%t0(B))
-f mMa) N 9 Te" v0 N >&&licatio".(valuate Q
(Left0(1) ? #tr(vM) ? Left0(2) ? #tr(vM) ? Q
Left0(B) ? #tr(vM) ? Left0(9) ? #tr(vM) ? Ri%t0(9))
-f mMa) N H Te" v0 N >&&licatio".(valuate Q
(Left0(1) ? #tr(vM) ? Left0(2) ? #tr(vM) ? Q
Left0(B) ? #tr(vM) ? Left0(9) ? #tr(vM) ? Q
Left0(H) ? #tr(vM) ? Ri%t0(H))
-f mMa) N A Te" v0 N >&&licatio".(valuate Q
(Left0(1) ? #tr(vM) ? Left0(2) ? #tr(vM) ? Q
Left0(B) ? #tr(vM) ? Left0(9) ? #tr(vM) ? Q
Left0(H) ? #tr(vM) ? Left0(A) ? #tr(vM) ? Ri%t0(A))
("d -f
-f 3 N 1 Te" v0 N (quatio"(vM)
' -" case te #3(4-0E o&tio" is used, ma1e sure tat te
' fu"ctio" (quatio"() s&ecifies te correct e)&ressio".
' 4o"ti"ue te summatio"
#um N #um J 2 * v0
-"te%ral(,) N #um * D C 2
:e)t i

-f R N 0 Te"
2ut&ut>rray(,, 1) N -"te%ral(,)
-f , I 1 J 1 Te"
-f -"te%ral(,) N 0 Te" &(rel N Q
+Lo%(>'s(-"te%ral(,) + -"te%ral(, + 1))) C Lo%(10)
-f -"te%ral(,) N -"te%ral(, + 1) Te" &(rel N 19
-f -"te%ral(,) RI 0 >"d -"te%ral(,) RI Q
-"te%ral(, + 1) Te" &(rel N +Lo%(>'s((-"te%ral(,) Q
+ -"te%ral(, + 1)) C -"te%ral(,))) C Lo%(10)
-f &(rel I = Te"
1Ma) N ,
()it 0or
("d -f
("d -f
("d -f
-f R N 1 Te"
Rom(,, 1) N -"te%ral(,)
0or ,, N 2 To ,
Rom(,, ,,) N (2 ; (2 * (,, + 1)) * Rom(,, ,, + 1) + Q
Rom(, + 1, ,, + 1)) C (2 ; (2 * (,, + 1)) + 1)
:e)t ,,
-f , I 1 J 1 Te"
-f Rom(,, ,) N 0 Te" &(rel N Q
+Lo%(>'s(Rom(,, ,) + Rom(, + 1, , + 1))) C Lo%(10)
-f Rom(,, ,) N Rom(, + 1, , + 1) Te" &(rel N 19
-f Rom(,, ,) RI 0 >"d Rom(,, ,) RI Rom(, + 1, , + 1) Q
Te" &(rel N +Lo%(>'s((Rom(,, ,) + Rom(, + 1, , + 1)) Q
C Rom(,, ,))) C Lo%(10)
("d -f
2ut&ut>rray(,, 1) N Rom(,, ,)
-f &(rel I = Te"
1Ma) N ,
()it 0or
("d -f
("d -f
Time2 N Timer
-"terval(,) N Rou"d(Time2 + Time1, 1)
2ut&ut>rray(,, 2) N -"terval(,)

>&&licatio".#tatus!ar N True
>&&licatio".#tatus!ar N P-teratio" ] P ? , ? Q
P. (ac successive iteratio" ta1es a'out P ? Q
Ptwice as lo"% as its immediate &redecessor.P
:e)t ,
Time2 N Timer
-"terval(,) N Rou"d(Time2 + Time1, 1)
2ut&ut>rray(,, 2) N -"terval(,)
=e'u%.3ri"t P-"te%ral(P ? , ? P) N P ? 2ut&ut>rray(,, 1)
=e'u%.3ri"t P-"terval(P ? , ? P) N P ? 2ut&ut>rray(,, 2)
' #elect te out&ut ra"%e
Ra"%e(a-").#elect
#electio".0ormula N f-"
#electio".2ffset(RMa) J 1, 0).#elect
#electio".Resi7e(1Ma), 2).#elect
' 2ut&ut te results
#electio".Galue N 2ut&ut>rray
' La'el te macro

>ctive4ell.#elect
>ctive4ell.4lear4omme"ts
>ctive4ell.>dd4omme"t
>ctive4ell.4omme"t.Gisi'le N 0alse
>ctive4ell.4omme"t.#a&e.$idt N 1*0
-f 3 N 0 >"d R N 0 Te" Q
>ctive4ell.4omme"t.Te)t Te)t6NPTra&e7>utoP ? Q
4r(10) ? PTra&e7oidal i"te%ratio" of P ? f0 ? Q
4r(10) ? Pfrom ) N P ? v> ? P to P ? v! ? Q
P, i" 'loc1 P ? a-" ? P,P ? Q
4r(10) ? Pto P ? = ? P si%"ifica"t di%its,P ? Q
P i" ma). P ? 1Ma) ? P iteratio"s.P ? Q
4r(10) ? P=ate6 P ? =ate ? P, Time6 P ? Time
-f 3 N 1 >"d R N 0 Te" Q
>ctive4ell.4omme"t.Te)t Te)t6NPTra&e7#&ecifyP ? Q
4r(10) ? PTra&e7oidal i"te%ratio" of P ? f0 ? Q
4r(10) ? Pfrom ) N P ? v> ? P to P ? v! ? Q
P, i" 'loc1 P ? a-" ? P,P ? Q
4r(10) ? Pto P ? = ? P si%"ifica"t di%its,P ? Q
P i" ma). P ? 1Ma) ? P iteratio"s.P ? Q
4r(10) ? P=ate6 P ? =ate ? P, Time6 P ? Time
-f 3 N 0 >"d R N 1 Te" Q
>ctive4ell.4omme"t.Te)t Te)t6NPRom'er%>utoP ? Q
4r(10) ? PRom'er% i"te%ratio" of P ? f0 ? Q
4r(10) ? Pfrom ) N P ? v> ? P to P ? v! ? Q
P, i" 'loc1 P ? a-" ? P,P ? Q
4r(10) ? Pto P ? = ? P si%"ifica"t di%its,P ? Q
P i" ma). P ? 1Ma) ? P iteratio"s.P ? Q
4r(10) ? P=ate6 P ? =ate ? P, Time6 P ? Time
-f 3 N 1 >"d R N 1 Te" Q
>ctive4ell.4omme"t.Te)t Te)t6NPRom'er%#&ecifyP ? Q
4r(10) ? PRom'er% i"te%ratio" of P ? f0 ? Q
4r(10) ? Pfrom ) N P ? v> ? P to P ? v! ? Q
P, i" 'loc1 P ? a-" ? P,P ? Q
4r(10) ? Pto P ? = ? P si%"ifica"t di%its,P ? Q
P i" ma). P ? 1Ma) ? P iteratio"s.P ? Q
4r(10) ? P=ate6 P ? =ate ? P, Time6 P ? Time
' >lert te user we" %oal is "ot reaced
>ctive4ell.#elect
#electio".2ffset(1Ma) + 1, 0).#elect
>ctive4ell.4lear4omme"ts
-f &(rel R = Te"
>ctive4ell.>dd4omme"t
>ctive4ell.4omme"t.Gisi'le N True
>ctive4ell.4omme"t.#a&e.$idt N 10H
>ctive4ell.4omme"t.Te)t Te)t6N Q
PTis "umerical i"te%ratio"P ? Q
4r(10) ? Pdid :2T reac P ? = ? P si%"ifica"tP ? Q
4r(10) ? Pdi%its i" P ? 1Ma) ? P iteratio"s.P ? Q
4r(10) ? P-"crease 1Ma)P ? Q
4r(10) ? Pa"dCor decrease =.P
("d -f
' Restore te i"&ut scree"
Ra"%e(a-").#elect
#electio".0ormula N f-"
>&&licatio".#tatus!ar N 0alse
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''*********************'''''''''''''''''''
'''''''''''''''''''* *'''''''''''''''''''
'''''''''''''''''''* (eri% *'''''''''''''''''''
'''''''''''''''''''* *'''''''''''''''''''
'''''''''''''''''''*********************'''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
Su& (eri%()
' >L(RT6 Tis fu"ctio" a"dCor its refere"ce derivative, if
' used for com&uti"% &(, ca" 'ecome u"defi"ed (as wit
' lo%()) for ) RN 0, a"d for sqrt()) for ) R 0). Tis may
' occur duri"% te com&utatio" eve" tou% M0 is "ear 'ut
' outside tat re%io". Tis ris1 'ecomes muc %reater at
' lar%er ,+values 'ecause te" te foot&ri"t of te
' al%oritm te" 'ecomes muc wider. -" suc a case, set
' 2&tio"! N 0 a"d start from te lowest ,+value, , N B.
' -f te &ro'lem &ersists, use forward or 'ac1ward
' derivatives i"stead, see >(B sectio"s @.2.2 a"d @.2 A,
' &ossi'ly wit e)te"ded &recisio" we" a smaller foot+
' &ri"t is "eeded.
' Tis macro com&utes te first derivative d0())Cd) at
' ) N )(0) of a fu"ctio" 0()) usi"% com&act ce"tral
' differe"ci"%, usi"% te al%oritm descri'ed i" sectio"
' @.2 of my 'oo1 P>dva"ced ()cel for scie"tific data
' a"alysisP, 2)ford 5"iversity 3ress, 2"d ed. 200K.
' Te macro sam&les (,J1)C2 equidista"t )+values o"
' eiter side of )(0), were , is a &ositive odd i"te%er6
' , N B, H, *, @, 11, 1B, or 1H.
' Te macro assumes tat te fu"ctio" 0()) is smoot
' a"d differe"tia'le, a"d as "o disco"ti"uities or
' si"%ularities, witi" te sam&li"% ra"%e of )+values
' &ro'ed 'y te macro. -f tat is "ot te case, a more
' a&&ro&riate, asymmetric differe"ci"% formula sould
' 'e used i"stead.
' (M>M3L(#6
' #ectio" @.2 i" (>B discusses com&uti"% te derivative i"
' %reat detail.
' 5#(R+#(L(4T>!L( 23T-2:#
' Te macro &rovides several o&tio"s tat are selected
' 'y setti"% several switces -: TD( G!> 42=(,
' immediately followi"% te dime"sio" stateme"ts. Te
' cose" o&tio"s are s&ecified i" te cell comme"t. Te
' followi"%, mutually tolera"t o&tio"s are &rovided6
' 2&tio"> N 06 use eiter delta N e&s;(1C,) or
' 2&tio"> N 16 use delta N vM0 * e&s;(1C,), te default
' 2&tio"! N 06 use te s&ecified ,+value, te default
' 2&tio"! N 16 use , N B (2) 1H
' 2&tio"4 N 06 do "ot com&ute &(, te default
' 2&tio"4 N 16 use a refere"ce value for te first
' derivative to com&ute &(
' !e aware tat te i"&ut 'o)es may ca"%e we" you select
' a differe"t o&tio".
' :ear te e"d of te macro, you ave a"oter o&tio", vi7.
' to dis&lay &( as com&uted, or as limited to te ra"%e
' from 0 to 19.
=im i >s -"te%er, , >s -"te%er, 2&tio"> >s -"te%er
=im 2&tio"! >s -"te%er, 2&tio"4 >s -"te%er
=im 4 >s Lo"%, R >s Lo"%
=im =elta(B To 1H) >s =ou'le, e&s >s =ou'le
=im 01 >s =ou'le, ,("d >s =ou'le, ,#tart >s =ou'le
=im &((B To 1H) >s =ou'le
=im =eriv(B To 1H) >s =ou'le, v00 >s =ou'le
=im v0(+K To K) >s =ou'le, vM(+K To K) >s =ou'le
=im vM0 >s =ou'le, vMM0 >s =ou'le
=im r%=eriv >s Ra"%e, r%0 >s Ra"%e, r%01 >s Ra"%e
=im r%_ >s Ra"%e, r%M >s Ra"%e
=im a0, a01, a_, aM, >0, a1
=im !0, !1, !2, !B, 400, 401, 41, f0, fM
=im Te)t>, Te)t!, Te)t4, Te)t=
' #elect your o&tio"s (if differe"t from teir
' curre"t values) 'y ca"%i"% te corres&o"di"%
' value6
' 2&tio"> N 06 use delta N e&s;(1C,)
' 2&tio"> N 16 use delta N vM0 * e&s;(1C,)
2&tio"> N 0
' 2&tio" ! N 06 use te s&ecified ,+value
' 2&tio" ! N 16 use , N B (2) 1H
2&tio"! N 0
' 2&tio"4 N 06 &( "ot com&uted
' 2&tio"4 N 16 use a refere"ce value for te first
' derivative to com&ute &(
2&tio"4 N 0
e&s N 2 ; (+H2)
, N B
' Read te value of ,
-f 2&tio"! N 1 Te" 8oTo !1
#et r%_ N >&&licatio".-"&ut!o)(3rom&t6N Q
P-"&ut o"e of tese odd i"te%ers6P ? 4r(1B) ? Q
PB, H, *, @, 11, 1B, or 1H< witP ? 4r(1B) ? Q
P'1' you will select all of tese.P ? Q
4r(1B) ? 4r(1B) ? Q
PTe value of , is located i" P, Ty&e6NK)
r%_.#elect
a_ N #electio".Galue
, N #electio".Galue
-f , N 1 Te" 2&tio"! N 16 8oTo !1
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe value of , sould occu&y a si"%le cell.P
("d
("d -f
' Ma1e sure tat , is a valid coice
-f , RI 1 Te"
-f , R 2.@ 2r , I 1H.1 2r (, I B.1 >"d , R 9.@) Q
2r (, I H.1 >"d , R A.@) 2r (, I *.1 >"d , R K.@) Q
2r (, I @.1 >"d , R 10.@) 2r (, I 11.1 >"d , R 12.@) Q
2r (, I 1B.1 >"d , R 19.@) Te"
Ms%!o) PMa1e , equal to o"e of te allowed coices.P
("d
("d -f
("d -f
-f , IN 2.@ >"d , RN B.1 Te" , N B
-f , IN 9.@ >"d , RN H.1 Te" , N H
-f , IN A.@ >"d , RN *.1 Te" , N *
-f , IN K.@ >"d , RN @.1 Te" , N @
-f , IN 10.@ >"d , RN 11.1 Te" , N 11
-f , IN 12.@ >"d , RN 1B.1 Te" , N 1B
-f , IN 19.@ >"d , RN 1H.1 Te" , N 1H
!16
' Read te fu"ctio" 0())
#et r%0 N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe fu"ctio" 0()) is located i" P, Ty&e6NK)
r%0.#elect
a0 N #electio".>ddress
f0 N #electio".0ormula
v00 N #electio".Galue
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe fu"ctio" 0()) sould occu&y a si"%le cell.P
("d
("d -f
' Read te varia'le )
#et r%M N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe &arameter ) is located i" P, Ty&e6NK)
r%M.#elect
aM N #electio".>ddress
fM N #electio".0ormula
vM0 N #electio".Galue
-f >'s(vM0) R 1 Te" 2&tio"> N 0
-f 2&tio"> N 0 Te" vMM0 N 1
-f 2&tio"> N 1 Te" vMM0 N vM0
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe )+value sould occu&y a si"%le cell.P
("d
("d -f
' 2&tio"ally, read te value of te first derivative
-f 2&tio"4 N 0 Te" 8oTo 400
#et r%01 N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe refere"ce value for te firstP ? 4r(1B) ? Q
Pderivative is located i" P, Ty&e6NK)
r%01.#elect
01 N r%01.Galue
a01 N r%01.>ddress
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe value of te first derivativeP ? 4r(1B) Q
? Psould occu&y a si"%le cell.P
("d
("d -f
4006
' Read were to de&osit te derivative
#et r%=eriv N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe calculated value of te firstP ? 4r(1B) ? Q
Pderivative sould 'e &laced i" P, Ty&e6NK)
r%=eriv.#elect
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe derivative sould 'e &laced i" a si"%le cell.P
("d
("d -f
' #am&le te "ecessary values of te fu"ctio" 0())
' 'y ca"%i"% te s&readseet values of )
-f 2&tio"! N 0 Te"
,#tart N ,
,("d N ,
("d -f
-f 2&tio"! N 1 Te"
,#tart N B
,("d N 1H
("d -f
0or , N ,#tart To ,("d #te& 2
=elta(,) N e&s ; (1 C ,)
0or i N +(, J 1) C 2 To (, J 1) C 2
vM(i) N vM0 J i * vMM0 * =elta(,)
r%M.#elect
#electio".Galue N vM(i)
r%0.#elect
v0(i) N #electio".Galue
:e)t i
i N i + 1
' (stimate te ,t derivative, v0_(,)
-f , N B Te" =eriv(,) N (+v0(+1) J v0(1)) Q
C (2 * vMM0 * =elta(,))
-f , N H Te" =eriv(,) N (v0(+2) + v0(2) Q
J K * (v0(1) + v0(+1))) C (12 * vMM0 * =elta(,))
-f , N * Te" =eriv(,) N (v0(B) + v0(+B) Q
J @ * (v0(+2) + v0(2)) J 9H * (v0(1) + v0(+1))) C Q
(A0 * vMM0 * =elta(,))
-f , N @ Te" =eriv(,) N (B * (v0(+9) + v0(9)) Q
J B2 * (v0(B) + v0(+B)) J 1AK * (v0(+2) + v0(2)) Q
J A*2 * (v0(1) + v0(+1))) C (K90 * vMM0 * =elta(,))
-f , N 11 Te" =eriv(,) N (2 * (v0(H) + v0(+H)) Q
J 2H * (v0(+9) + v0(9)) J 1H0 * (v0(B) + v0(+B)) Q
J A00 * (v0(+2) + v0(2)) J 2100 * (v0(1) + v0(+1))) Q
C (2H20 * vMM0 * =elta(,))
-f , N 1B Te" =eriv(,) N (H * (v0(+A) + v0(A)) Q
J *2 * (v0(H) + v0(+H)) J 9@H * (v0(+9) + v0(9)) Q
J 2200 * (v0(B) + v0(+B)) J *92H * (v0(+2) + v0(2)) Q
J 2B*A0 * (v0(1) + v0(+1))) C (2**20 * vMM0 * =elta(,))
-f , N 1H Te" =eriv(,) N (1H * (v0(*) + v0(+*)) Q
J 29H * (v0(+A) + v0(A)) J 1@11 * (v0(H) + v0(+H)) Q
J @HHH * (v0(+9) + v0(9)) J BH0BH * (v0(B) + v0(+B)) Q
J 10H10H * (v0(+2) + v0(2)) J B1HB1H * (v0(1) + v0(+1))) Q
C (BA0BA0 * vMM0 * =elta(,))
:e)t ,
, N , + 2
' 3lace su&&orti"% i"formatio" i" a cell comme"t
-f 2&tio"> N 0 Te" Te)t> N PP
-f 2&tio"> N 1 Te" Te)t> N P M0 *P
-f 2&tio"! N 0 Te" Te)t! N ,
-f 2&tio"! N 1 Te" Te)t! N PB to 1HP
-f 2&tio"4 N 0 Te" Te)t4 N P"ot P
-f 2&tio"4 N 1 Te" Te)t4 N PP
-f 2&tio"4 N 1 Te" Te)t= N P usi"%P ? 4r(10) ? Q
P te value of 0'(ref) i" P ? a01
r%=eriv.#elect
>ctive4ell.#elect
>ctive4ell.4lear4omme"ts
>ctive4ell.>dd4omme"t
>ctive4ell.4omme"t.Gisi'le N 0alse
>ctive4ell.4omme"t.#a&e.$idt N 1H0
>ctive4ell.4omme"t.#a&e.Dei%t N 100
>ctive4ell.4omme"t.Te)t Te)t6NP=eriv v *P ? 4r(10) ? Q
4r(10) ? Pcom&utes te first derivative 0' of P ? Q
4r(10) ? P 0P ? f0 ? P i" cell P ? a0 ? 4r(10) ? Q
P at ) N P ? vM0 ? P i" cell P ? aM ? 4r(10) ? Q
Pdelta N P ? Te)t> ? Pe&silo";(1C,)P ? 4r(10) ? Q
P, N P ? Te)t! ? P, &( is P ? Te)t4 ? Q
Pcom&utedP ? Te)t= ? 4r(10) ? Q
Pdate6 P ? =ate ? P, time6 P ? Time
' =is&lay te result
r%=eriv.#elect
-f 2&tio"! N 0 Te"
,#tart N ,
,("d N ,
("d -f
-f 2&tio"! N 1 Te"
,#tart N B
,("d N 1H
("d -f
0or , N ,#tart To ,("d #te& 2
#electio".Galue N =eriv(,)
-f 2&tio"4 N 0 Te" 8oTo 401
' -"clude &(
-f 01 N 0 Te" &((,) N +Lo%(>'s(=eriv(,))) Q
C Lo%(10)
-f 01 RI 0 >"d (=eriv(,) + 01) RI 0 Te" Q
&((,) N +Lo%(>'s((=eriv(,) + 01) C 01)) C Lo%(10)
-f 01 RI 0 >"d (=eriv(,) + 01) N 0 Te" Q
&((,) N P1HP

' 2&tio"al out&ut clea"u&< if u"wa"ted,
' comme"t+out te "e)t two li"es of code

-f &((,) R 0 Te" &((,) N 0
-f &((,) I 19 Te" &((,) N 19
' 2ut&ut &(
#electio".2ffset(0, 1).#elect
#electio".Galue N &((,)
#electio".2ffset(0, +1).#elect
4016
#electio".2ffset(1, 0).#elect
:e)t ,
' 4lea" u&
r%M.#elect
#electio".Galue N vM0
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''*******************************''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''* (eri%* *''''''''''''''
''''''''''''''* *''''''''''''''
''''''''''''''*******************************''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(
' Tis macro uses ce"tral differe"ci"% to estimate te
' first derivative d0())Cd) of a fu"ctio" 0()) of a si"%le
' varia'le ) at ) N )0. -t is 'ased o" a detailed a"alysis
' of systematic a"d ca"cellatio" "oise i" ce"tral
' differe"ci"%. Te teoretical ,ustificatio" for tis
' al%oritm is e)&lai"ed i" sectio"s @.2.@ a"d @.2.10 of my
' 2012 'oo1 o" >dva"ced ()cel, B
rd
ed., &&. 91A+92B.
' Te macro assumes te &rovisio"al value )0 * 2;(+H2C,)
' for te ste& si7e =elta used i" suc calculatio"s, a"d
' wit tis value estimates te derivatives required to
' fi"d a 'etter value for =elta, wit wic it com&utes
' its fi"al a"swer.
' Tis macro as so far 'ee" su',ected o"ly to &relimi"ary
' testi"%, a"d is terefore la'eled as a 'eta versio". Te
' &relimi"ary testi"% su%%ests tat te macro yields
' a"swers %ood to a'out 10 decimal &laces for , N B, to
' a'out 11 decimals for , N H, 12 for , N *, a"d 1B for
' , N @. Tere seems to 'e "o adva"ta%e i" %oi"% 'eyo"d
' , N @, 'ecause ca"cellatio" "oise te" 'ecomes domi"a"t,
' e)ce&t we" avera%i"% is used. (Dowever, si%"ifica"t
' avera%i"% "oticea'ly slows dow" te macro, ardly wort
' te %ai" of a'out o"e more si%"ifica"t decimal, a"d
' terefore is "ot im&leme"ted ere.) Te macro ca" &rovide
' a"swers for , of u& to 1H, were , is a" odd &ositive
' i"te%er lar%er ta" 2.
' -f tis macro &roves relia'le u"der more ri%orous
' testi"%, it will re&lace =eriv i" te Macro!u"dle, a"d
' its al%oritm will 'e i"cor&orated i"to te 3ro&a%atio"
' a"d #olver>id macros.
' 3L(>#( TRE -T 25T, a"d re&ort a"y deficie"cies,
' su%%estio"s or comme"ts to me at my email,
' rdelevieW'owdoi".edu.
' TD>:L#U
' -:35T
' -" successive i"&ut 'o)es, te user is as1ed to &oi"t to
' tree i"dividual s&readseet cells, wic sould co"tai"6
' (1) Te desired value of ,, te "um'er of equidista"t
' data sam&les to 'e ta1e". Te coice is restricted to
' te seve" odd i"te%ers B, H, *, @, 11, 1B, a"d 1H.
' > P1P will %e"erate te first four (or, wit a mi"or
' ca"%e i" te macro, u& to all seve") results.
' (2) Te fu"ctio" to 'e differe"tiated.
' (B) Te value of ) at wic te derivative of te
' fu"ctio" sould 'e evaluated. 0or , N 1 te locatio"
' %ive" will s&ecify te left+most cell of a row of
' seve" cells.
' :otes6
' Te fu"ctio" i" te cell &rovided i" i"&ut]2 sould 'e
' te actual e)&ressio" as a fu"ctio" of te )+value
' listed i" te locatio" s&ecified i" i"&ut]B.
' -t is easiest to arra"%e tese tree i"&ut cell i" a
' si"%le s&readseet row, wit te out&ut cell(s) to teir
' ri%t.
' 25T35T
' -" a"swer to a fourt query, te user sould i"dicate te
' s&readseet locatio" were te out&ut sould a&&ear. $e"
' all seve" results are requested, tey will a&&ear i" a
' si"%le row, starti"% i" te selected cell wit te result
' for , N B, a"d movi"% successively to te ri%t for
' i"creasi"%ly i%er ,+values. -" tat case ma1e sure tat
' te te" required seve" out&ut cells do "ot co"tai"
' i"formatio" tat sould "ot 'e overwritte".
' #5!R25T-:(#
' :o su'routi"es are "eeded.
' >33L-4>!-L-TE
' 4e"tral differe"ci"% assumes tat te fu"ctio" a"d te
' derivatives i"volved i" te calculatio" are PsmootP,
' i.e., tat tey co"tai" "o disco"ti"uities or si"%ula+
' rities. Moreover, te sam&li"% used sould "ot reac
' re%io"s were te fu"ctio" is ill+defi"ed, suc as
' "e%ative )+values for a square root, or "o"+&ositive
' "um'ers for a lo%aritm. -" te latter cases, lateral
' differe"ci"% or oter metods sould 'e used i"stead.
' $e" a&&lied to a fu"ctio" close to a disco"ti"uity,
' si"%ularity, or 'ou"dary of a&&lica'ility, it may 'e
' advisa'le to use e)te"ded &recisio", &era&s wit
' forward or 'ac1ward differe"ci"%, i" order to stay away
' from suc disco"ti"uities, si"%ularities, or oter
' 'ou"daries a"d still acieve sufficie"t "umerical
' &recisio".
' (M>M3L(#6
' >(B sectio"s @.2@ a"d @.2.10 descri'e te uses of tis
' macro %reat detail. -t ca" 'e used as a %e"eral re&lace+
' me"t for =eriv, a"d is su',ect to te same co"strai"ts.
' #(L(4T-:8 >: 23T-M>L ,+G>L5(
' $e" 0()) as "o disco"ti"uities or si"%ularities,
' use , N @ for 'est accuracy, ofte" wit &( IN 19.
' $e" te "earest disco"ti"uity or si"%ularity i" 0()) is
' at 0(y), select , suc tat a's(foot&ri"t) R a's()+y).
' 5se te followi"% a&&ro)imate values as your %uide6
' , N B a's(foot&ri"t) R 0.001
' , N H a's(foot&ri"t) R 0.01
' , N * a's(foot&ri"t) R 0.1
' , N @ a's(foot&ri"t) R 0.H
' Te" ru" =eriv1, a"d cec1 te actual foot&ri"t value i"
' te cell comme"t. -f tis value as e)ceeded a's()+y),
' lower your ,+value a"d re&eat. -f tis i"dicates tat
' eve" , N B as too lar%e a foot&ri"t for your &ro'lem,
' switc to lateral differe"ci"%.
' Te macro fails (a"d alerts te user) we" te "ecessary
' i%er derivative is com&uted as equal to 7ero.
Su& (eri%*()
=im i >s -"te%er, , >s -"te%er
=im ,("d >s -"te%er, ,#tart >s -"te%er
=im :(B To 1*) >s -"te%er
=im 2&tio"> >s -"te%er, 2&tio"! >s -"te%er, Z >s -"te%er
=im 4 >s Lo"%, R >s Lo"%
=im ''(B To 1*) >s =ou'le, cc(B To 1*) >s =ou'le
=im dd(B To 1*) >s =ou'le
=im =elta(B To 1*) >s =ou'le, =elta2&t(B To 1*) >s =ou'le
=im =eriv(B To 1*) >s =ou'le, =eriv_(B To 1*) >s =ou'le
=im =eriv2&t(B To 1*) >s =ou'le, (ca"c(B To 1*) >s =ou'le
=im (est >s =ou'le, (o&t(B To 1*) >s =ou'le, e&s >s =ou'le
=im 0(+@ To @) >s =ou'le, 0oot&ri"t(B To 1*) >s =ou'le
=im 00 >s =ou'le, 01 >s =ou'le, ,, >s =ou'le
=im &=elta(B To 1*) >s =ou'le, &=elta2&t(B To 1*) >s =ou'le
=im &(ca"c(B To 1*) >s =ou'le, &(est(B To 1*) >s =ou'le
=im &(o&t(B To 1*) >s =ou'le
=im M(+@ To @) >s =ou'le, M0 >s =ou'le, MM0 >s =ou'le
=im r%=eriv >s Ra"%e, r%0 >s Ra"%e, r%01 >s Ra"%e
=im r%_ >s Ra"%e, r%M >s Ra"%e
=im a0, a01, a_, aM, f0, fM
=im -f0-sZero>"dM-sZero
=im -"&ut4oice_, -"&ut0u"ctio"0, -"&ut3aramaterM
=im 2ut&utLocatio", #tart=eriv_, Te)t>, Te)t!
' -"ter"ally, te macro sets a"d uses two mutually
' tolera"t o&tio"s tat ave te followi"% fu"ctio"s6
' 2&tio"> N 06 use delta N 2;(+H2C,) we" M0 close to 0
' 2&tio"> N 16 use delta N M0 * 2;(+H2C,)
' 2&tio"! N 06 use te s&ecified ,+value we" , I 2
' 2&tio"! N 16 use , N B (2) @ we" , is s&ecified as 1
' (wic ca" 'e ca"%ed to B (2) 1H if so desired)
e&s N 2 ; (+H2)
2&tio"> N 1
2&tio"! N 0
, N B
Z N 0
''(B) N A ' ''(,) N 1 C '(,)
''(H) N B0
''(*) N 190
''(@) N AB0
''(11) N 2**2
''(1B) N 12012
''(1H) N H19K0
''(1*) N 21K*@0
cc(B) N 9.HB29AAH1KBAK9(+1*
cc(H) N A.0@0B1KKK99BAHA(+1*
cc(*) N A.@B9@KA9AB9HBH1(+1*
cc(@) N *.9KB1***2@29@9B(+1*
cc(11) N *.K*H91K0*KK2B21(+1*
cc(1B) N K.1*BKA9*9122KHB(+1*
cc(1H) N K.910*A9B*A@0@A(+1*
cc(1*) N K.A09*1@9B2K9K0*(+1*
' Read te value of ,
-"&ut4oice_6
#et r%_ N >&&licatio".-"&ut!o)(3rom&t6N Q
P-"&ut te cell locatio" were , is stored.P ? 4r(1B) ? Q
PTe &ossi'le ,+values are B, H, *, @, 11, 1B,P ? 4r(1B) ? Q
Por 1H, wile 1 selects all seve" ,+values.P, Ty&e6NK)
r%_.#elect
a_ N #electio".Galue
,, N #electio".Galue
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe value of , sould occu&y a si"%le cell.P
8oTo -"&ut4oice_
("d -f
' Ma1e sure tat , is a valid coice
-f ,, IN 0.H >"d ,, R 1.H Te" 2&tio"! N 1
-f ,, R 0.H 2r ,, I 1H.H 2r (,, I 1.1 >"d ,, R 2.@) Q
2r (,, I B.1 >"d ,, R 9.@) 2r (,, I H.1 >"d ,, R A.@) Q
2r (,, I *.1 >"d ,, R K.@) 2r (,, I @.1 >"d ,, R 10.@) Q
2r (,, I 11.1 >"d ,, R 12.@) 2r (,, I 1B.1 >"d ,, R 19.@) Q
Te"
Ms%!o) PMa1e , equal to o"e of te allowed coices.P
8oTo -"&ut4oice_
("d -f
-f ,, IN 2.@ >"d ,, RN B.1 Te" , N B
-f ,, IN 9.@ >"d ,, RN H.1 Te" , N H
-f ,, IN A.@ >"d ,, RN *.1 Te" , N *
-f ,, IN K.@ >"d ,, RN @.1 Te" , N @
-f ,, IN 10.@ >"d ,, RN 11.1 Te" , N 11
-f ,, IN 12.@ >"d ,, RN 1B.1 Te" , N 1B
-f ,, IN 19.@ >"d ,, RN 1H.1 Te" , N 1H
' Read te fu"ctio" 0())
-"&ut0u"ctio"06
#et r%0 N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe fu"ctio" 0()) is located i" P, Ty&e6NK)
r%0.#elect
a0 N #electio".>ddress
f0 N #electio".0ormula
00 N #electio".Galue
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe fu"ctio" 0()) sould occu&y a si"%le cell.P
8oTo -"&ut0u"ctio"0
("d -f
' Read te varia'le )
-"&ut3arameterM6
#et r%M N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe &arameter ) is located i" P, Ty&e6NK)
r%M.#elect
aM N #electio".>ddress
fM N #electio".0ormula
M0 N #electio".Galue
-f >'s(M0) R 1 Te" 2&tio"> N 0
-f 2&tio"> N 0 Te" MM0 N 1
-f 2&tio"> N 1 Te" MM0 N M0
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 4 RI 1 2r R RI 1 Te"
Ms%!o) PTe )+value sould occu&y a si"%le cell.P
8oTo -"&ut3arameterM
("d -f
' Read were to de&osit te derivative
2ut&utLocatio"6
#et r%=eriv N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe calculated value of te firstP ? 4r(1B) ? Q
Pderivative sould 'e &laced i"P, Ty&e6NK)
r%=eriv.#elect
' =etermi"e te i"&ut si7e
4 N #electio".4olum"s.4ou"t
R N #electio".Rows.4ou"t
-f 2&tio"! N 0 >"d (4 RI 1 2r R RI 1) Te"
Ms%!o) PTe derivative sould 'e &laced i" a si"%le cell.P
8oTo 2ut&utLocatio"
("d -f
-f 2&tio"! N 1 >"d (4 RI 1 2r R RI 1) Te"
Ms%!o) P3lease s&ecify te locatio"P ? 4r(1B) ? Q
Pof te left+most out&ut cell.P
8oTo 2ut&utLocatio"
("d -f
' #u&&ress scree" u&dati"%
>&&licatio".#cree"5&dati"% N 0alse
' #am&le te "ecessary values of te fu"ctio" 0())
' 'y ca"%i"% te s&readseet values of )
'2" (rror 8oTo Da"dler
-f 2&tio"! N 0 Te"
,#tart N ,
,("d N ,
("d -f
-f 2&tio"! N 1 Te"
,#tart N B
' D2$ T2 4D>:8( TD( R>:8( 20 ,+G>L5(# #D2$: 02R , N 16
' TD( =(0>5LT G>L5( 20 ,("d -# #(T T2 @< -0 E25 $>:T T2
' =-#3L>E M2R( (2R 0($(R) TD>: TD( 0-R#T 025R ,+G>L5(#,
' -: TD( :(MT L-:( 4D>:8( TD( G>L5( 20 ,("d >442R=-:8LE,
' T2 53 T2 1H. :2T(6 02R ,("d 2:LE 5#( 2:( 20 TD( -:T(8(R
' G>L5(# H, *, @, 11, 1B, 2R 1H.

,("d N @

("d -f
0or , N ,#tart To ,("d #te& 2
=elta(,) N MM0 * e&s ; (1 C ,)
0or i N +(, + 1) C 2 To (, + 1) C 2
M(i) N M0 J i * =elta(,)
r%M.#elect
#electio".Galue N M(i)
r%0.#elect
0(i) N #electio".Galue
:e)t i
i N i + 1
' (stimate te first derivative, =eriv(,)
-f , N B Te" =eriv(,) N (0(1) + 0(+1)) Q
C (2 * =elta(,))
-f , N H Te" =eriv(,) N (0(+2) + 0(2) Q
J K * (0(1) + 0(+1))) C (12 * =elta(,))
-f , N * Te" =eriv(,) N (0(B) + 0(+B) Q
J @ * (0(+2) + 0(2)) J 9H * (0(1) + 0(+1))) Q
C (A0 * =elta(,))
-f , N @ Te" =eriv(,) N (B * (0(+9) + 0(9)) Q
J B2 * (0(B) + 0(+B)) J 1AK * (0(+2) + 0(2)) Q
J A*2 * (0(1) + 0(+1))) C (K90 * =elta(,))
-f , N 11 Te" =eriv(,) N (2 * (0(H) + 0(+H)) Q
J 2H * (0(+9) + 0(9)) J 1H0 * (0(B) + 0(+B)) Q
J A00 * (0(+2) + 0(2)) J 2100 * (0(1) + 0(+1))) Q
C (2H20 * =elta(,))
-f , N 1B Te" =eriv(,) N (H * (0(+A) + 0(A)) Q
J *2 * (0(H) + 0(+H)) J 9@H * (0(+9) + 0(9)) Q
J 2200 * (0(B) + 0(+B)) J *92H * (0(+2) + 0(2)) Q
J 2B*A0 * (0(1) + 0(+1))) C (2**20 * =elta(,))
-f , N 1H Te" =eriv(,) N (1H * (0(*) + 0(+*)) Q
J 29H * (0(+A) + 0(A)) J 1@11 * (0(H) + 0(+H)) Q
J @HHH * (0(+9) + 0(9)) J BH0BH * (0(B) + 0(+B)) Q
J 10H10H * (0(+2) + 0(2)) J B1HB1H * (0(1) + 0(+1))) Q
C (BA0BA0 * =elta(,))
:(,) N 0
#tart=eriv_6
' (stimate te _t derivative, =eriv_(,)
0or i N +(, J 1) C 2 To (, J 1) C 2
M(i) N M0 J i * =elta(,)
r%M.#elect
#electio".Galue N M(i)
r%0.#elect
0(i) N #electio".Galue
:e)t i
i N i + 1
-f , N B Te" =eriv_(,) N ((0(2) + 0(+2)) Q
J 2 * (0(+1) + 0(1))) C (2 * (=elta(,)) ; (,))
-f , N H Te" =eriv_(,) N (0(B) + 0(+B) Q
J 9 * (0(+2) + 0(2)) J H * (0(1) + 0(+1))) Q
C (2 * (=elta(,)) ; (,))
-f , N * Te" =eriv_(,) N (0(9) + 0(+9) Q
J A * (0(+B) + 0(B)) J 19 * (0(2) + 0(+2) Q
J 0(+1) + 0(1))) C (2 * (=elta(,)) ; (,))
-f , N @ Te" =eriv_(,) N (0(H) + 0(+H) Q
J K * (0(+9) + 0(9)) J 2* * (0(B) + 0(+B)) Q
J 9K * (0(+2) + 0(2)) J 92 * (0(1) + 0(+1))) Q
C (2 * (=elta(,)) ; (,))
-f , N 11 Te" =eriv_(,) N (0(A) + 0(+A) Q
J 10 * (0(+H) + 0(H)) J 99 * (0(9) + 0(+9)) Q
J 110 * (0(+B) + 0(B)) J 1AH * (0(2) + 0(+2)) Q
J 1B2 * (0(+1) + 0(1))) C (2 * (=elta(,)) ; (,))
-f , N 1B Te" =eriv_(,) N (0(*) + 0(+*) Q
J 12 * (0(+A) + 0(A)) J AH * (0(H) + 0(+H)) Q
J 20K * (0(+9) + 0(9)) J 92@ * (0(B) + 0(+B)) Q
J H*2 * (0(+2) + 0(2)) J 92@ * (0(1) + 0(+1))) Q
C (2 * (=elta(,)) ; (,))
-f , N 1H Te" =eriv_(,) N (0(K) + 0(+K) Q
J 19 * (0(+*) + 0(*)) J @0 * (0(A) + 0(+A)) Q
J BH0 * (0(+H) + 0(H)) J @10 * (0(9) + 0(+9)) Q
J 1ABK * (0(+B) + 0(B)) J 2002 * (0(2) + 0(+2)) Q
J 19B0 * (0(+1) + 0(1))) C (2 * (=elta(,)) ; (,))
-f , N 1* Te" =eriv_(,) N (0(@) + 0(+@) Q
J 1A * (0(+K) + 0(K)) J 11@ * (0(*) + 0(+*)) Q
J H99 * (0(+A) + 0(A)) J 1*00 * (0(H) + 0(+H)) Q
J BK0K * (0(+9) + 0(9)) J A1KK * (0(B) + 0(+B)) Q
J *0*2 * (0(+2) + 0(2)) J 9KA2 * (0(1) + 0(+1))) Q
C (2 * (=elta(,)) ; (,))

-f >'s(=eriv_(,)) RN e&s Te"
=elta(,) N 2 * =elta(,)
:(,) N :(,) J 1
-f :(,) R H Te" 8oTo #tart=eriv_
-f :(,) N H Te" Q
Ms%!o) PTe "eeded i%er derivative is 7ero< P ? 4r(10) Q
? Pte al%oritm failed at , N P ? ,6 8oTo :
("d -f
=elta(,) N (=elta(,)) C (2 ; :(,))

' Ta1e care of a &redicta'le &ro'lem
-f >'s(00) RN e&s >"d >'s(M0) RN e&s Te" Q
M0 N 0.0000000000016 Z N 1
-f0-sZero>"dM-sZero6
-f Z N +1 Te" M0 N +0.000000000001
-f Z RI 0 Te"
r%M.#elect
#electio".Galue N M0
r%0.#elect
00 N #electio".Galue
("d -f

-f >'s(=eriv_(,)) R e&s Te" Q
Ms%!o) PTe value of te _t derivative P Q
? Pis (too close to) 7ero.P6 8oTo (

' 4om&ute =elta2&t a"d &(2&t
dd(,) N (cc(,) * ''(,) C (, + 1)) ; (1 C ,)
=elta2&t(,) N dd(,) * ((>'s(00) J >'s(M0 * =eriv(,))) Q
C (>'s(=eriv_(,)))) ; (1 C ,)

(o&t(,) N >'s((, * cc(,)) C ((, + 1) * dd(,)) Q
* ((>'s(00) J >'s(M0 * =eriv(,))) C =eriv(,)) Q
* ((>'s(=eriv_(,))) C (>'s(00) J >'s(M0 * =eriv(,)))) Q
; (1 C ,))
(ca"c(,) N cc(,) * (>'s(00) J >'s(M0 * =eriv(,))) Q
C (=elta(,) * >'s(=eriv(,)))
&=elta(,) N +Lo%(=elta2&t(,)) C Lo%(10)
&=elta2&t(,) N +Lo%(=elta(,)) C Lo%(10)
&(o&t(,) N +Lo%(>'s((o&t(,))) C Lo%(10)
&(ca"c(,) N +Lo%((ca"c(,)) C Lo%(10)
&(est(,) N +Lo%((o&t(,) J B * (ca"c(,)) C Lo%(10)
' Re+sam&le te data wit =elta2&t
0or i N +(, + 1) C 2 To (, + 1) C 2
M(i) N M0 J i * =elta2&t(,)
r%M.#elect
#electio".Galue N M(i)
r%0.#elect
0(i) N #electio".Galue
:e)t i
i N i + 1
' >%ai" com&ute te first derivative, =eriv(,),
' 'ut "ow wit =elta2&t(,)
-f , N B Te" =eriv2&t(,) N (+0(+1) J 0(1)) Q
C (2 * =elta2&t(,))
-f , N H Te" =eriv2&t(,) N (0(+2) + 0(2) Q
J K * (0(1) + 0(+1))) C (12 * =elta2&t(,))
-f , N * Te" =eriv2&t(,) N (0(B) + 0(+B) Q
J @ * (0(+2) + 0(2)) J 9H * (0(1) + 0(+1))) C Q
(A0 * =elta2&t(,))
-f , N @ Te" =eriv2&t(,) N (B * (0(+9) + 0(9)) Q
J B2 * (0(B) + 0(+B)) J 1AK * (0(+2) + 0(2)) Q
J A*2 * (0(1) + 0(+1))) C (K90 * =elta2&t(,))
-f , N 11 Te" =eriv2&t(,) N (2 * (0(H) + 0(+H)) Q
J 2H * (0(+9) + 0(9)) J 1H0 * (0(B) + 0(+B)) Q
J A00 * (0(+2) + 0(2)) J 2100 * (0(1) + 0(+1))) Q
C (2H20 * =elta2&t(,))
-f , N 1B Te" =eriv2&t(,) N (H * (0(+A) + 0(A)) Q
J *2 * (0(H) + 0(+H)) J 9@H * (0(+9) + 0(9)) Q
J 2200 * (0(B) + 0(+B)) J *92H * (0(+2) + 0(2)) Q
J 2B*A0 * (0(1) + 0(+1))) C (2**20 * =elta2&t(,))
-f , N 1H Te" =eriv2&t(,) N (1H * (0(*) + 0(+*)) Q
J 29H * (0(+A) + 0(A)) J 1@11 * (0(H) + 0(+H)) Q
J @HHH * (0(+9) + 0(9)) J BH0BH * (0(B) + 0(+B)) Q
J 10H10H * (0(+2) + 0(2)) J B1HB1H * (0(1) + 0(+1))) Q
C (BA0BA0 * =elta2&t(,))

=im =eriv2&t3lus(B To 1*) >s =ou'le
=im =eriv2&tMi"(B To 1*) >s =ou'le
=im =elta2&t3lus(B To 1*) >s =ou'le
=im =elta2&tMi"(B To 1*) >s =ou'le

-f Z N 1 Te"
=eriv2&t3lus(,) N =eriv2&t(,)
=elta2&t3lus(,) N =elta2&t(,)
Z N +1
8oTo -f0-sZero>"dM-sZero
("d -f
-f Z N +1 Te"
=eriv2&tMi"(,) N =eriv2&t(,)
=elta2&tMi"(,) N =elta2&t(,)
-f =eriv2&t3lus(,) * =eriv2&tMi"(,) I 0 Te"
=eriv2&t(,) N (=eriv2&t3lus(,) J =eriv2&tMi"(,)) C 2
=elta2&t(,) N =elta2&t3lus(,) J =elta2&tMi"(,) C 2
("d -f
("d -f

-f Z N +1 Te" M0 N 0
r%M.#elect
#electio".Galue N M0
&=elta2&t(,) N Rou"d(&=elta2&t(,), 9)
&(o&t(,) N Rou"d(&(o&t(,), 2)
&(est(,) N Rou"d(&(est(,) + 0.0H, 1)
-f &(est(,) I 19 Te" &(est(,) N P19P
0oot&ri"t(,) N 0.H * (, J 1) * (2 ; :(,)) * =elta(,)
-f (, + 1) * =elta2&t(,) I 0oot&ri"t(,) Te" Q
0oot&ri"t(,) N 0.H * (, + 1) * =elta2&t(,)
' Release scree" u&dati"%
>&&licatio".#cree"5&dati"% N 0alse
' 3lace su&&orti"% i"formatio" i" a cell comme"t
-f 2&tio"> N 0 Te" Te)t> N PP
-f 2&tio"> N 1 Te" Te)t> N P M0 *P
' =is&lay te result
r%=eriv.#elect
-f 2&tio"! N 1 Te" Q
#electio".2ffset(0, (, + B) C 2).#elect
>ctive4ell.#elect
>ctive4ell.4lear4omme"ts
>ctive4ell.>dd4omme"t
>ctive4ell.4omme"t.Gisi'le N 0alse
>ctive4ell.4omme"t.#a&e.$idt N 1H0
>ctive4ell.4omme"t.#a&e.Dei%t N 120
>ctive4ell.4omme"t.Te)t Te)t6NP=eriv1 v @ ('eta)P ? 4r(10) Q
? 4r(10) ? Pcom&utes te first derivative 0' of P ? Q
4r(10) ? P 0P ? f0 ? P i" cell P ? a0 ? 4r(10) ? Q
P at )NP ? M0 ? P i" cell P ? aM ? 4r(10) ? Q
P, N P ? , ? P, &(est(P ? , ? P) I P ? &(est(,) ? Q
4r(10) ? P&=elta2&t(P ? , ? P) N P ? &=elta2&t(,) ? Q
4r(10) ? P0oot&ri"t(P ? , ? P) N P ? M0 ? Q
P &lus or mi"us P ? 0oot&ri"t(,) ? 4r(10) ? Q
Pdate6 P ? =ate ? P, time6 P ? Time
#electio".Galue N =eriv2&t(,)

' !e%i" of o&tio"al out&uts6
' #electio".2ffset(1, 0).#elect
' #electio".Galue N &(o&t(,)
' #electio".2ffset(1, 0).#elect
' #electio".Galue N &(ca"c(,)
' #electio".2ffset(1, 0).#elect
' #electio".Galue N &(est(,)
' #electio".2ffset(+B, 0).#elect

' ("d of o&tio"al out&uts

:6
:e)t ,
8oTo (
Da"dler6
-f (rr.:um'er N 1B Te"
Ms%!o) PTe fu"ctio" ca""ot 'e evaluated at o"e of teP ? Q
4r(1B) ? Psam&led )+values. Retry wit a lower ,+value.P
8oTo (
(lse-f (rr.:um'er RI 1B Te" Q
Ms%!o) P>" error occurred, wit error "um'er P ? Q
(rr.:um'er ? P6P ? 4r(1B) ? P'P ? Q
(rr.=escri&tio" ? P'.P ? 4r(1B) ? 4r(1B) ? Q
P3ress 2L. #orry, te macro will e"d.P
8oTo (
("d -f
(6
' 4lea" u&
r%M.#elect
#electio".0ormula N fM
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''*********************'''''''''''''''''''
'''''''''''''''''''* *'''''''''''''''''''
'''''''''''''''''''* (eri%Scan *'''''''''''''''''''
'''''''''''''''''''* *'''''''''''''''''''
'''''''''''''''''''*********************'''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
Su& (eri%Scan()
' > sim&lified versio" of =eriv() for sca""i"% te first
' derivative as a fu"ctio" of &=elta N +lo%(=elta) usi"%
' ce"tral differe"ci"%, wit =elta0 N M(0) * e&s;1C, as
' its a"cor. Te ra"%e of =elta+values used i" te macro
' is set i" te macro code ,ust ,ust a'ove te la'el 46
' >" i"creme"t of i 'y 90 ca"%es &=elta 'y o"e. 0or
' "e%ative i+values (i" te ra"%e of &redomi"a"tly
' systematic errors) te ra"%e may "eed to 'e restricted
' at i%er ,+values.
' Te i"&ut values are most co"ve"ie"tly arra"%ed i" a row
' of ad,ace"t cells, wit (from left to ri%t) te values
' of ,, 0()), a"d ). $e" so or%a"i7ed, te first derivative
' will a&&ear 'elow 0()), a"d &=elta 'elow ), leavi"% s&ace
' 'elow , for a s&readseet calculatio" of &( we" a
' refere"ce value for te first derivative is availa'le,
' ma1i"% te out&ut co"ve"ie"t to &lot.
' (M>M3L(#
' Te fi%ures i" >(B sectio"s @.2.K a"d @.2.@ were com&uted
' wit =eriv#ca"
=im i >s -"te%er, , >s -"te%er, 1 >s -"te%er
=im c0 >s Lo"%, cM >s Lo"%, r0 >s Lo"%, rM >s Lo"%
=im =elta(B To 1H, +120 To B00) >s =ou'le
=im e&s(B To 1H) >s =ou'le
=im v=eriv(+120 To B00) >s =ou'le, v0(+K To K) >s =ou'le
=im vM(+K To K) >s =ou'le
=im r%=eriv >s Ra"%e, r%0 >s Ra"%e
=im r%_ >s Ra"%e, r%M >s Ra"%e
=im a0, a_, aM, f0(0), fM(0)
' Read te value of ,
#et r%_ N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe ,+value is located i" P, Ty&e6NK)
r%_.#elect
, N r%_.Galue
a_ N r%_.>ddress
e&s(,) N (1.11022B029A2HB2(+1A) ; (1 C ,)
' Read te fu"ctio" 0())
#et r%0 N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe fu"ctio" 0()) is located i" P, Ty&e6NK)
r%0.#elect
a0 N r%0.>ddress
f0(0) N r%0.0ormula
v0(0) N r%0.Galue
' =etermi"e te i"&ut si7e
c0 N #electio".4olum"s.4ou"t
r0 N #electio".Rows.4ou"t
-f c0 RI 1 2r r0 RI 1 Te"
Ms%!o) PTe fu"ctio" 0()) sould 'eP ? Q
4r(1B) ? P located i" a si"%le cell.P
("d
("d -f
' Read te varia'le )
#et r%M N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe &arameter ) is located i" P, Ty&e6NK)
r%M.#elect
aM N r%M.>ddress
fM(0) N r%M.0ormula
vM(0) N r%M.Galue
' =etermi"e te i"&ut si7e
cM N #electio".4olum"s.4ou"t
rM N #electio".Rows.4ou"t
-f cM RI 1 2r rM RI 1 Te"
Ms%!o) PTe )+value souldP ? Q
4r(1B) ? Poccu&y a si"%le cell.P
("d
("d -f
' #tart te calculatio"
>&&licatio".#cree"5&dati"% N 0alse
' D(R( #(L(4T TD( R>:8( 20 i+G>L5(# T2 !( 5#(=
0or i N +90 To B00
46
=elta(,, i) N >'s(vM(0)) ; (1 C ,) * e&s(,) * (0.01 ; (i C K0))
0or 1 N +(, J 1) C 2 To (, J 1) C 2
2" (rror 8oTo (rrorDa"dler4
vM(1) N vM(0) J 1 * =elta(,, i)
r%M.#elect
#electio".Galue N vM(1)
r%0.#elect
v0(1) N #electio".Galue
:e)t 1
8oTo =
(rrorDa"dler46
, N , + 2
Ms%!o) PGalue of , is lowered to P ? ,
8oTo 4
=6
' 4om&ute v=eriv
-f , N B Te" v=eriv(i) N (+v0(+1) J v0(1)) Q
C (2 * =elta(,, i))
-f , N H Te" v=eriv(i) N (v0(+2) + K * v0(+1) Q
J K * v0(1) + v0(2)) C (12 * =elta(,, i))
-f , N * Te" v=eriv(i) N (v0(B) + v0(+B) Q
J @ * (v0(+2) + v0(2)) J 9H * (v0(1) + v0(+1))) Q
C (A0 * =elta(,, i))
-f , N @ Te" v=eriv(i) N (B * (v0(+9) + v0(9)) J Q
B2 * (v0(B) + v0(+B)) J 1AK * (v0(+2) + v0(2)) Q
J A*2 * (v0(1) + v0(+1))) C (K90 * =elta(,, i))
-f , N 11 Te" v=eriv(i) N (2 * (v0(H) + v0(+H)) J Q
2H * (v0(+9) + v0(9)) J 1H0 * (v0(B) + v0(+B)) Q
J A00 * (v0(+2) + v0(2)) J 2100 * (v0(1) + v0(+1))) Q
C (2H20 * =elta(,, i))
-f , N 1B Te" v=eriv(i) N (H * (v0(+A) + v0(A)) Q
J *2 * (v0(H) + v0(+H)) J 9@H * (v0(+9) + v0(9)) Q
J 2200 * (v0(B) + v0(+B)) J *92H * (v0(+2) + v0(2)) Q
J 2B*A0 * (v0(1) + v0(+1))) C (2**20 * =elta(,, i))
-f , N 1H Te" v=eriv(i) N (1H * (v0(*) + v0(+*)) Q
J 29H * (v0(+A) + v0(A)) J 1@11 * (v0(H) + v0(+H)) Q
J @HHH * (v0(+9) + v0(9)) J BH0BH * (v0(B) + v0(+B)) Q
J 10H10H * (v0(+2) + v0(2)) J B1HB1H * (v0(1) + v0(+1))) Q
C (BA0BA0 * =elta(,, i))
:e)t i
' 4lea" u&
r%M.#elect
#electio".0ormula N fM(0)
' >dd a cell comme"t
#electio".2ffset(9, +1).#elect
>ctive4ell.#elect
>ctive4ell.4lear4omme"ts
>ctive4ell.>dd4omme"t
>ctive4ell.4omme"t.Gisi'le N 0alse
>ctive4ell.4omme"t.#a&e.$idt N 1BH
>ctive4ell.4omme"t.#a&e.Dei%t N A0
>ctive4ell.4omme"t.Te)t Te)t6NP=eriv#ca" v *P Q
? 4r(10) ? P,NP ? , ? P i" cell P ? a_ ? 4r(10) Q
? P0())P ? f0(0) ? P i" cell P ? a0 ? 4r(10) Q
? P)NP ? vM(0) ? P i" cell P ? aM Q
? 4r(10) ? P=ate6 P ? =ate ? P, Time6 P ? Time
' $rite te result
'''#electio".2ffset(9, +1).#elect
'''#electio".2ffset(H, 0).#elect
0or i N +90 To B00
#electio" N v=eriv(i)
#electio".2ffset(0, 1).#elect
#electio" N +Lo%(=elta(,, i)) C Lo%(10)
#electio".2ffset(1, +1).#elect
:e)t i
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''*********************************'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''* Semi$Integration and *'''''''''''''
'''''''''''''* Semi$(i##erentiation *'''''''''''''
'''''''''''''* *'''''''''''''
'''''''''''''*********************************'''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tis macro &erforms semi+i"te%ratio" a"d semi+differe"+
' tiatio", s&eciali7ed (de)co"volutio" metods a&&lica'le
' to &ro'lems of &la"ar eat co"ductio", &la"ar diffusio",
' a"d si%"al tra"smissio" alo"% a ca'le wit u"iformly
' distri'uted resista"ce a"d ca&acita"ce, see L. !. 2ldam,
' >"al. 4em. 91 (1@A@) 1121< 99 (1@*2) 1@A.
' Te macro uses a sim&le semi+i"te%ratio" al%oritm< for
' more so&isticated al%oritms see L. !. 2ldam ? _. 4.
' Myla"d, 0u"dame"tals of electrocemical scie"ce, >cademic
' 3ress 1@@9. Te semi+differe"tial is te" fou"d 'y ta1i"%
' first differe"ces.
' -" te co"te)t of li"ear swee& voltammetry or cyclic
' voltammetry (wic are 'ot metods used i" electro+
' cemical a"alysis), semi+i"te%ratio" ca" co"vert a
' curre"t+time+volta%e curve i"to te corres&o"di"%
' steady+state curre"t+volta%e curve, wic is ofte"
' muc easier to i"ter&ret qua"titatively. 0or a discussio"
' of suc a" a&&licatio", see a"y moder" electrocemical
' te)t'oo1, or co"sult my Dow to use ()cel i" a"alytical
' cemistry, 4am'rid%e 5"iv. 3ress, 2001, &&. 2H*+2AB.

' #5!R25T-:(#6
' Te drivers #emi-"te%rate() a"d #emi=iffere"tiate()
' call te su'routi"e #emi
' -:35T6
' Te i"&ut data must 'e equidista"t, a"d sould 'e
' stored i" a si"%le, co"ti"uous colum".
' 25T35T6
' Te resulti"% tra"sformed out&ut data will 'e writte"
' i" te colum" immediately to te ri%t of te i"&ut
' data. Tat colum" is terefore 'est left free.
' 3R24(=5R(6
' 4all te macro, a"d i"&ut te data 'y followi"% te
' i"structio"s wit its i"&ut 'o)es.
Su& SemiIntegrate()
=im i-"t=if >s -"te%er
i-"t=if N 1
4all #emi(i-"t=if)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Semi(i##erentiate()
=im i-"t=if >s -"te%er
i-"t=if N +1
4all #emi(i-"t=if)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Semi(i-"t=if)
' Te macro uses a sim&le semi+i"te%ratio" al%oritm due
' to 2ldam wic is adequate to illustrate te a&&roac.
' Te semi+differe"tial is te" fou"d 'y ta1i"% first
' differe"ces.

' Te i"&ut data sould 'e stored i" a si"%le, co"ti"uous
' colum". Te resulti"% tra"sformed out&ut data will 'e
' writte" i" te colum" immediately to te ri%t of te
' i"&ut data. Tat colum" is terefore 'est left free.
' 3arameter "ames used6
' c"ma) "um'er of colum"s i"
' i%li%ted data 'loc1
' r"ma) "um'er of rows i"
' i%li%ted data 'loc1
' data>rray array of all i"&ut data
' r" i"de) s&ecifyi"% row "um'er
' i" i"&ut data array
=im c"Ma) >s -"te%er, , >s -"te%er, 1 >s -"te%er
=im : >s -"te%er, r"Ma) >s -"te%er
=im a >s =ou'le, s >s =ou'le, deltaTime >s =ou'le
=im myRa"%e >s Ra"%e
=im i"&ut=ata >s Garia"t, semi-"t >s Garia"t
=im out&ut=ata >s Garia"t, testGalue >s Garia"t
=im Z >s Garia"t
=im my>ddress, >"s
: N 0
' -"&ut te time i"creme"t a"d use it
' to com&ute te &arameter s
-f i-"t=if N 1 Te"
deltaTime N Q
-"&ut!o)(P("ter te time i"creme"ts, i" seco"ds.P, Q
P#emi-"te%ratio" -"&ut!o) 16 Time i"creme"tsP)
(lse
deltaTime N Q
-"&ut!o)(P("ter te time i"creme"ts, i" seco"ds.P, Q
P#emi=iffere"tiatio" -"&ut!o) 16 Time i"creme"tsP)
("d -f
s N #qr(>'s(deltaTime))
' ("ter te i"&ut data
-f i-"t=if N 1 Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe curre"t values are located i"6P, Title6N Q
P#emi-"te%ratio" -"&ut!o) 26 -"&ut dataP, Ty&e6NK)
(lse
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe curre"t values are located i"6P, Title6N Q
P#emi=iffere"tiatio" -"&ut!o) 26 -"&ut dataP, Ty&e6NK)
("d -f
myRa"%e.#elect
-f #electio".4olum"s.4ou"t RI 1 Te"
("d
(lse
r"Ma) N #electio".Rows.4ou"t
i"&ut=ata N #electio".Galue
semi-"t N #electio".Galue
out&ut=ata N #electio".Galue
my>ddress N #electio".>ddress
("d -f
' 4ec1 tat te out&ut will "ot overwrite valua'le data
#electio".2ffset(0, 1).#elect
testGalue N #electio".Galue
0or , N 1 To r"Ma)
Z N testGalue(,, 1)
-f -s(m&ty(Z) Te"
: N :
(lse
: N : J 1
("d -f
:e)t ,
-f : I 0 Te"
>"s N Ms%!o)(PTere are data i" te s&ace were P Q
? Pte out&ut will 'eP ? 4r(1B) ? P writte". P Q
? P3roceed a"yway a"d overwrite tose dataOP, Q
v'Ees:o)
-f >"s N v':o Te"
#electio".2ffset(0, +1).#elect
("d
("d -f
("d -f
' 4om&ute te semi+i"te%ratio"
Re=im 3(1 To r"Ma)) >s =ou'le
3(1) N 1
0or , N 2 To r"Ma)
3(,) N 3(, + 1) * (, + 1.H) C (, + 1)
:e)t ,
0or 1 N 1 To r"Ma)
a N 0
0or , N 1 To 1
a N a J 3(1 + , J 1) * i"&ut=ata(,, 1)
:e)t ,
semi-"t(1, 1) N a * s
:e)t 1
-f i-"t=if N +1 Te"
0or 1 N 2 To r"Ma)
out&ut=ata(1, 1) N Q
(semi-"t(1, 1) + semi-"t(1 + 1, 1)) C deltaTime
:e)t 1
semi-"t(1, 1) N PP
(lse
0or 1 N 1 To r"Ma)
out&ut=ata(1, 1) N semi-"t(1, 1)
:e)t 1
("d -f
' $rite te result
#electio".Galue N out&ut=ata
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''*********************'''''''''''''''''''
'''''''''''''''''''* *'''''''''''''''''''
'''''''''''''''''''* Mapper *'''''''''''''''''''
'''''''''''''''''''* *'''''''''''''''''''
'''''''''''''''''''*********************'''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 11, May 2012
' 35R32#(6
'
' Tis macro reads a i%li%ted 'loc1 of data, i"cludi"%
' a)is la'els at its to& a"d left+a"d side. Tis format
' was cose" i" order to 'e com&ati'le wit tat of ()cel
' 2+= %ra&s a"d B+= surface &lots. Te macro se&arates
' tese la'els, co"verts te remai"i"% data i"to R8! colors
' wit eiter a %ray scale (for i4olor N 10 trou% 12) or
' o"e of tree sam&le color scemes &rovided (i4olor N 20
' to 92), a"d uses tese to ma1e a %ra&. -f you wis, loo1
' at te su'routi"es !itMa&10 trou% !itMa&92 to see ow
' it is do"e, te" add your ow" color sceme.
'
' Tis macro is most useful we" tere are ma"y (100 or
' more) data &oi"ts i" 'ot directio"s. -f "ot, ()cel's B+=
' &lot may well 'e te more satisfactory. !ot of tem
' require te i"&ut data to 'e equidista"t i" ) as well as
' i" y. $e" te &lot co"tai"s relatively few data &oi"ts,
' te sim&le, 'ili"ear i"ter&olatio" to %e"erate &i)el
' values ca" cause star+li1e artifacts, as if o"e loo1s at
' a street lam& trou% a fi"ely wove" clot. Tis could 'e
' remedied 'y usi"% a more so&isticated i"ter&olatio"
' sceme.
'
' Te resulti"% fi%ure ca" 'e moved, e"lar%ed or reduced,
' a""otated, a"d modified as a"y oter ME %ra&. =ata
' &oi"ts, curves, a"d te)t ca" 'e added, scales ca" 'e
' modified or deleted, etc.
'
' -" order to facilitate dis&layi"% scales, te macro
' cec1s weter te to& left cell i" te i%li%ted
' array is em&ty, a"d te cells 'elow it a"d to its ri%t
' are filled. :ote, owever, tat te scales dis&layed
' merely reflect te "um'ers &rovided i" te to& row a"d
' te left colum", a"d are :2T fu"ctio"al, so tat modi+
' fyi"% tem afterwards will "ot rescale or oterwise
' affect te ma&. Moreover, 'ecause tis is a macro rater
' ta" a fu"ctio", te ma& does "ot res&o"d to su'seque"t
' ca"%es i" te i"&ut data u"til te macro is called a%ai"
' to u&date te i"&ut i"formatio".
'
' $e" te to& left cell is "ot em&ty 'ut co"tai"s a 1,
' te macro will "ot autoscale, 'ut will i"stead as1 te
' user for a mi"imum a"d ma)imum values for its scale, as
' may 'e useful for com&ari"% differe"t ma&s. -" order to
' avoid artifacts from e)ceedi"% te mi"imum a"dCor ma)imum
' values, use te widest ra"%e tat will accomodate all ma&s.
'
' #5!R25T-:(#6
'
' Te drivers Ma&&er0 trou% Ma&&erBBB call te mai" routi"e
' Ma&&er, wic i" tur" calls o" a "um'er of su'routi"es6
' !itma&Deader, $rite>$ord, $rite>Lo"%, $rite>3i)el,
' $rite>!yte, a"d !itma&0 trou% !itma&BBB. > si"%le di%it
' i"dicates a %radual scale, a dou'le di%it a ste&wise scale,
' a"d a tri&le di%it a scale tat as its ma)imum color i"
' te middle. -f you wa"t to add a differe"t color sceme,
' ,ust add o"e as !itma&9 wit a corres&o"di"% driver
' (Ma&&er9), usi"% te e)isti"% code as e)am&le. -f you use
' te M!Tool'ar or M!Me"u, ma1e sure to i"clude te "ew
' driver(s) tere.
'
' -:35T6
'
' Te macro requires a" i"&ut array to%eter wit te
' corres&o"di"% scales, wic must 'e &laced i" te to&
' row a"d i" te left+a"d colum", leavi"% te to& left+
' a"d cell em&ty.
'
' 25T35T6
'
' Te resulti"% ma& ca" 'e resi7ed, rescaled, moved, a"d
' oterwise ma"i&ulated as a"y %ra&. Eou ca" also i"sert
' te)t, overlay curves, add i"serts, etc.
'
' 3R24(=5R(6
'
' Di%li%t te array to 'e ma&&ed to%eter wit te
' corres&o"di"% scales, wic must 'e &laced i" te
' to& row a"d i" te left+a"d colum", leavi"% te
' to& left+a"d cell em&ty. Te" call te macro.
'
' $>R:-:86
'
' Tis macro %oes 25T#-=( 20 ()cel i" order to write
' a 'itma&, wic is te" re+im&orted as ''ac1%rou"d'
' for te %ra&. =e&e"di"% o" ow te rest of te 2ffice
' 'u"dle is co"fi%ured (or i" its a'se"ce, we" o"ly
' ()cel is loaded) te macro may "ot always ru" &ro&erly.
'
' 4R(=-T6
'
' Tis macro was writte" 'y $illiam 4rai% of te 8eor%etow"
' 5"iversity 4emistry =e&artme"t.
'
' (M>M3L(6
'
' 5se of tis macro is illustrated trou%out (>B, starti"%
' wit sectio" 1.H. #ectio" K.22 descri'es ow to modify
' Ma&&er`s !itMa& to select your ow" color sceme.
Su& Mapper:()
=im i4olor
i4olor N 0
4all Ma&&er(0)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper::()
=im i4olor
i4olor N 10
4all Ma&&er(10)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper:::()
=im i4olor
i4olor N 100
4all Ma&&er(100)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper*()
=im i4olor
i4olor N 1
4all Ma&&er(1)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper**()
=im i4olor
i4olor N 11
4all Ma&&er(11)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper***()
=im i4olor
i4olor N 111
4all Ma&&er(111)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper;()
=im i4olor
i4olor N 2
4all Ma&&er(2)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper;;()
=im i4olor
i4olor N 22
4all Ma&&er(22)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper;;;()
=im i4olor
i4olor N 222
4all Ma&&er(222)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper+()
=im i4olors
i4olor N B
4all Ma&&er(B)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper++()
=im i4olor
i4olor N BB
4all Ma&&er(BB)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper+++()
=im i4olor
i4olor N BBB
4all Ma&&er(BBB)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper<()
=im i4olors
i4olor N 9
4all Ma&&er(9)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& Mapper(i4olor >s -"te%er)
' :ome"clature used6
'
' i"&ut>rray te i%li%ted 'loc1 co"tai"i"% te data
' &lus (at its to& a"d left+a"d side)
' eiter a)is la'els or s&ace for tem.
' scaled>rray te i"&ut array scaled to fit te ra"%e
' from 0 to 2HH.
' value>rray te i"ter&olated array. -t as as ma"y
' terms as tere are &i)els i" te &lotti"%
' area. >ll terms are dou'le &recisio", i"
' te ra"%e from 0 to 2HH
' &i)el>rray te value array e)&ressed i" terms of
' i"te%ers.
' r" i"&ut data ei%t.
' & &i)el (i"stead or row) ei%t, starti"% at
' te 'ottom wit 0.
' cw i"&ut data widt.
' &w &i)el (i"stead of colum") widt, starti"%
' at te left wit 0.
' cwMa)+1, rMa)+1 "um'er of i"&ut data, i" terms of
' colum"s a"d rows res&ectively.
' Ma), wMa) "um'er of &i)els, i" terms of ei%t a"d
' widt res&ectively.
' DD, $$ "um'er of &i)els &er i"&ut data &oi"t, i"
' terms of ei%t a"d widt res&ectively.
=im c: >s -"te%er, cw >s -"te%er, cwMa) >s -"te%er
=im & >s -"te%er, &w >s -"te%er
=im r >s -"te%er, r: >s -"te%er, rMa) >s -"te%er
=im i >s -"te%er, iD >s -"te%er, i$ >s -"te%er
=im , >s -"te%er
=im 2ut&ut0ile:um'er >s -"te%er
=im ma)Galue >s =ou'le, mi"Galue >s =ou'le
=im 3roduct >s Lo"%
=im MLa'elMa) >s =ou'le, MLa'elMi" >s =ou'le
=im ELa'elMa) >s =ou'le, ELa'elMi" >s =ou'le
=im a1 >s -"te%er, a2 >s -"te%er, !1 >s -"te%er
=im D >s -"te%er, DD >s -"te%er, #cale >s -"te%er
=im Ma) >s -"te%er, Ma)0 >s -"te%er ' &lot &i)el ei%t
=im wMa) >s -"te%er, wMa)0 >s -"te%er ' &lot &i)el widt
=im "s >s -"te%er ' "um'er of data series
=im 3 >s -"te%er, S >s -"te%er
=im w >s -"te%er, $$ >s -"te%er, w#cale >s -"te%er
=im 1 >s =ou'le, 2 >s =ou'le
=im w1 >s =ou'le, w2 >s =ou'le
=im -"&ut>rray >s Garia"t, scaled>rray >s Garia"t
=im &i)el>rray >s Garia"t, Galue>rray >s Garia"t
=im 2ut&ut0ile:ame >s #tri"%, #eet"ame >s #tri"%
=im myRa"%e >s Ra"%e, r%Ma) >s Ra"%e, r%Mi" >s Ra"%e
=im >"swer, Tis#eet
' Read te i"&ut>rray
!e%i"6
-"&ut>rray N #electio".Galue
cwMa) N #electio".4olum"s.4ou"t
rMa) N #electio".Rows.4ou"t
' -f i"&ut area was "ot i%li%ted
-f rMa) N 1 >"d cwMa) N 1 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o, PMa&&erP)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et myRa"%e N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
myRa"%e.#elect
("d -f
8oTo !e%i"
("d -f
>&&licatio".#cree"5&dati"% N 0alse
-f rMa) R B Te"
Ms%!o) PTe 'loc1, i"cludi"% (s&ace for)P ? Q
4r(1B) ? Pa scale at te to& row,P ? Q
4r(1B) ? Psould 'e at least B cells i%.P
("d
("d -f
-f cwMa) R B Te"
Ms%!o) PTe 'loc1, i"cludi"% (s&ace for)P ? Q
4r(1B) ? Pa scale at te left+most colum",P ? Q
4r(1B) ? Psould 'e at least B cells wide.P
("d
("d -f
' Ma1e sure tat te to& left cell is eiter em&ty or
' co"tai"s a 1, a"d tat its two "earest "ei%'ors are
' "ot em&ty. Te macro will autoscale we" it fi"ds a"
' em&ty to& left cell< a value of 1 i" tat cell will
' &rom&t two i"&ut 'o)es, for te mi"imum a"d ma)imum
' values res&ectively of te scale to 'e used.
'
' :ote6 te to& row a"d te left+most colum" are used
' for creati"% te ma& scales, a"d will :2T 'e &lotted.
' 2" te s&readseet you mi%t ma1e tem clearly
' differe"t from te rest of te array, e.%., 'y usi"%
' italics, 'oldface, a"dCor color.
3 N 0
S N 0
-f -"&ut>rray(1, 1) N 1 Te" 3 N 16 S N 1
-f -s(m&ty(-"&ut>rray(1, 1)) 2r -s:ull(-"&ut>rray(1, 1)) Q
Te" 3 N 3 J 1
-f 3 N 0 Te"
Ms%!o) PMa1e sure tat te to& left cellP ? Q
4r(1B) ? Pof te i%li%ted area is em&ty.P
("d
("d -f
-f -s(m&ty(-"&ut>rray(2, 1)) 2r -s:ull(-"&ut>rray(2, 1)) Q
Te" 3 N 3 J 1
-f -s(m&ty(-"&ut>rray(1, 2)) 2r -s:ull(-"&ut>rray(1, 2)) Q
Te" 3 N 3 J 1
-f 3 RI 1 Te"
Ms%!o) P Ma1e sure tat te to& row a"d teP ? Q
4r(1B) ? Pleft+a"d colum" co"tai" te &lot scales,P ? Q
4r(1B) ? Pwile leavi"% te left to& cell em&ty.P
("d
("d -f
' 0i"d ma)imum a"d mi"imum values i" MLa'els a"d ELa'els
ELa'elMa) N -"&ut>rray(2, 1)
ELa'elMi" N -"&ut>rray(2, 1)
0or r: N B To rMa)
-f -"&ut>rray(r:, 1) I ELa'elMa) Te" ELa'elMa) N Q
-"&ut>rray(r:, 1)
-f -"&ut>rray(r:, 1) R ELa'elMi" Te" ELa'elMi" N Q
-"&ut>rray(r:, 1)
:e)t r:
MLa'elMa) N -"&ut>rray(1, 2)
MLa'elMi" N -"&ut>rray(1, 2)
0or c: N B To cwMa)
-f -"&ut>rray(1, c:) I MLa'elMa) Te" MLa'elMa) N Q
-"&ut>rray(1, c:)
-f -"&ut>rray(1, c:) R MLa'elMi" Te" MLa'elMi" N Q
-"&ut>rray(1, c:)
:e)t c:
' 0i"d ma)imum a"d mi"imum values i" i"&ut>rray
ma)Galue N -"&ut>rray(2, 2)
mi"Galue N -"&ut>rray(2, 2)
0or r: N 2 To rMa)
0or c: N 2 To cwMa)
-f -"&ut>rray(r:, c:) I ma)Galue Te" ma)Galue N Q
-"&ut>rray(r:, c:)
-f -"&ut>rray(r:, c:) R mi"Galue Te" mi"Galue N Q
-"&ut>rray(r:, c:)
:e)t c:
:e)t r:
' -f S N 1 as1 for &ossi'ly differe"t ma)imum a"d mi"imum values
>&&licatio".#cree"5&dati"% N True
-f S N 1 Te"
mi"Galue N -"&ut!o)(PTe mi"imum value is6 P, Q
P(5se tis or a lower value)P, mi"Galue)
ma)Galue N -"&ut!o)(PTe mi"imum value is6 P, Q
P(5se tis or a i%er value)P, ma)Galue)
("d -f
>&&licatio".#cree"5&dati"% N 0alse
' #cale te i"&ut>rray o" a scale from 0 to 2HH
Re=im scaled>rray(0 To rMa), 0 To cwMa))
0or r: N 2 To rMa)
0or c: N 2 To cwMa)
scaled>rray(r:, c:) N 2HH * (-"&ut>rray(r:, c:) Q
+ mi"Galue) C (ma)Galue + mi"Galue)
:e)t c:
:e)t r:
' =raw %ra&
cw N 4olum"s(1).$idt
r N Rows(1).Dei%t
#eet"ame N >ctive#eet.:ame
4arts.>dd
>ctive4art.4artTy&e N )lME#catter
>ctive4art.Locatio" $ere6N)lLocatio">s2',ect, :ame6N#eet"ame
>ctive4art.>)es()lGalue).#elect
$it >ctive4art.>)es()lGalue)
.Mi"imum#cale-s>uto N True
.Ma)imum#cale-s>uto N True
.Ma,or5"it-s>uto N True
.Mi"or5"it-s>uto N True
.4rosses N )l>utomatic
.Ma,orTic1Mar1 N )l4ross
.Mi"orTic1Mar1 N )l:o"e
.Tic1La'el3ositio" N )lLow
("d $it
#electio".Tic1La'els.:um'er0ormat N P8e"eralP
>ctive4art.>)es()lGalue).Ma,or8ridli"es.#elect
#electio".=elete
>ctive4art.>)es()l4ate%ory).#elect
$it >ctive4art.>)es()l4ate%ory)
.Mi"imum#cale-s>uto N True
.Ma)imum#cale-s>uto N True
.Ma,or5"it-s>uto N True
.Mi"or5"it-s>uto N True
.4rosses N )l>utomatic
.Ma,orTic1Mar1 N )l4ross
.Mi"orTic1Mar1 N )l:o"e
.Tic1La'el3ositio" N )lLow
("d $it
$it #electio".!order
.$ei%t N )lDairli"e
.Li"e#tyle N )l>utomatic
("d $it
>ctive4art.3lot>rea.#elect
$it #electio".!order
.4olor-"de) N H*
.$ei%t N )lDairli"e
.Li"e#tyle N )l4o"ti"uous
("d $it
' Rou"d &lot area ei%t a"d widt to i"te%er
' multi&les of te data i" te i"&ut array
w#cale N 1
-f wMa) I cwMa) + 1 Te" w#cale N -"t(wMa)0 C (cwMa) + 2))
#cale N 1
-f Ma) I rMa) + 1 Te" #cale N -"t(Ma)0 C (rMa) + 2))
wMa) N (cwMa) + 2) * w#cale
Ma) N (rMa) + 2) * #cale
DD N Ma) C (rMa) + 2)
$$ N wMa) C (cwMa) + 2)
' 4alculate value>rray for c" N 2 to cwMa)
Re=im Galue>rray(0 To Ma), 0 To wMa)) >s =ou'le
Re=im &i)el>rray(0 To Ma), 0 To wMa)) >s -"te%er
0or c: N 2 To cwMa)
D N Ma)
iD N -"t(D C DD)
1 N (iD J 1) + D C DD
2 N D C DD + iD
Galue>rray(Ma), (c: + 2) * $$) N Q
1 * scaled>rray(iD J 2, c:)
:e)t c:
0or c: N 2 To cwMa)
0or D N 0 To Ma) + 1
iD N -"t(D C DD)
1 N (iD J 1) + D C DD
2 N D C DD + iD
Galue>rray(D, (c: + 2) * $$) N Q
1 * scaled>rray(iD J 2, c:) Q
J 2 * scaled>rray(iD J B, c:)
:e)t D
:e)t c:
' 4alculate all of value>rray
0or D N 0 To Ma)
0or w N 1 To wMa) + 1
i$ N -"t(w C $$)
w1 N (i$ J 1) + w C $$
w2 N w C $$ + i$
Galue>rray(D, w) N w1 * Galue>rray(D, i$ * $$) J Q
w2 * Galue>rray(D, (i$ J 1) * $$)
:e)t w
:e)t D
' 4o"vert &i)el values to i"te%ers
0or D N 0 To Ma)
0or w N 0 To wMa)
&i)el>rray(D, w) N 4-"t(Galue>rray(D, w))
:e)t w
:e)t D
'4reate, write, a"d close te 'itma& file
2ut&ut0ile:ame N P4olorMa&.!M3P
2ut&ut0ile:um'er N 1
2&e" 2ut&ut0ile:ame 0or !i"ary >ccess $rite >s Q
]2ut&ut0ile:um'er

4all !itma&Deader(Ma), wMa))
-f i4olor N 2 Te" 4all !itMa&0(Ma), wMa), &i)el>rray)
-f i4olor N 10 Te" 4all !itMa&00(Ma), wMa), &i)el>rray)
-f i4olor N 100 Te" 4all !itMa&000(Ma), wMa), &i)el>rray)
-f i4olor N 1 Te" 4all !itMa&1(Ma), wMa), &i)el>rray)
-f i4olor N 11 Te" 4all !itMa&11(Ma), wMa), &i)el>rray)
-f i4olor N 111 Te" 4all !itMa&111(Ma), wMa), &i)el>rray)
-f i4olor N 2 Te" 4all !itMa&2(Ma), wMa), &i)el>rray)
-f i4olor N 22 Te" 4all !itMa&22(Ma), wMa), &i)el>rray)
-f i4olor N 222 Te" 4all !itMa&222(Ma), wMa), &i)el>rray)
-f i4olor N B Te" 4all !itMa&B(Ma), wMa), &i)el>rray)
-f i4olor N BB Te" 4all !itMa&BB(Ma), wMa), &i)el>rray)
-f i4olor N BBB Te" 4all !itMa&BBB(Ma), wMa), &i)el>rray)
-f i4olor N 9 Te" 4all !itMa&9(Ma), wMa), &i)el>rray)
4lose ]2ut&ut0ile:um'er
Tis#eet N >ctive#eet.:ame
>ctive4art.3lot>rea.0ill.5ser3icture 2ut&ut0ile:ame
' Ma)imi7e te &lot area
>ctive4art.3lot>rea.#elect
#electio".0ill.Gisi'le N True
' #et te a)is la'els
>ctive4art.>)es()l4ate%ory).#elect
>ctive4art.>)es()l4ate%ory).Mi"imum#cale N MLa'elMi"
>ctive4art.>)es()l4ate%ory).Ma)imum#cale N MLa'elMa)
>ctive4art.>)es()lGalue).#elect
>ctive4art.>)es()lGalue).Mi"imum#cale N ELa'elMi"
>ctive4art.>)es()lGalue).Ma)imum#cale N ELa'elMa)
' Remove all mar1ers
"s N >ctive4art.#eries4ollectio".4ou"t
0or i N 1 To "s
>ctive4art.#eries4ollectio"(i).#elect
>ctive4art.#eries4ollectio"(i).Mar1er#tyle N )l:o"e
:e)t i
>ctive4art.4art>rea.#elect
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Tis routi"e writes a mi"imal H9 'yte 'itma& file eader.
Pri%ate Su& Bitmap6eader(& >s -"te%er, &w >s -"te%er)

' Galues for &i)el widt &$, &i)el ei%t &D, -ma%e#i7e+
' -"!yte a"d Total0ile#i7e ca"%e wit te ima%e si7e.
'
=im RowLe"%t-"!ytes >s Lo"%
=im -ma%e#i7e-"!yte >s Lo"%
=im Total0ile#i7e >s Lo"%

' 4alculate tree values "eeded write eader. -"
' &articular, row le"%t is te "um'er of 'ytes
' rou"ded u& to te "e)t =$2R= (9 'yte) 'ou"dary.
RowLe"%t-"!ytes N (((&w J 1) * B) ^ 9) * 9
-ma%e#i7e-"!yte N RowLe"%t-"!ytes * &
Total0ile#i7e N H9 J (& * RowLe"%t-"!ytes)
' $rite te !itma&0ileDeader

$rite>$ord 1@**K ' 'fTy&e Te two caracters !M
$rite>Lo"% Total0ile#i7e ' 'f#i7e Deaders J ima%e
$rite>Lo"% 0 ' 'fReserved1?2 Two words of 7ero.
$rite>Lo"% H9 ' 'f2ff!its !yte offset to ima%e.
' $rite te !itma&-"foDeader
$rite>Lo"% 90 ' 'i#i7e !-TM>3-:02D(>=(R si7e N 90.
$rite>Lo"% &w ' 'i$idt -ma%e widt.
$rite>Lo"% & ' 'iDei%t -ma%e widt.
$rite>$ord 1 ' 'i3la"es >lways 1.
$rite>$ord 29 ' 'i!it4ou"t >lways 29 'its &er &i)el.
$rite>Lo"% 0 ' 'i4om&ressio" :o com&ressio" N 0
$rite>Lo"% -ma%e#i7e-"!yte
' 'i#i7e-ma%e -ma%e si7e i" 'ytes
$rite>Lo"% B000 ' 'iM3els3erMeter > safe value
$rite>Lo"% B000 ' 'iE3els3erMeter > safe value
$rite>Lo"% 0 ' 'i4lr5sed >lways 0
$rite>Lo"% 0 ' 'i4lr-m&orta"t >lways 0
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap:(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)

' 0or a co"ti"uous %ray+scale, witout color,
' from 'lac1 to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1
RedGal N &i)el>rray(D, w)
8ree"Gal N &i)el>rray(D, w)
!lueGal N &i)el>rray(D, w)
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap::(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or quasi+co"tour dia%ram usi"% @ differe"t
' sades of %ray, from 'lac1 to wite
=im D >s -"te%er, w >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

-f &i)el>rray(D, w) R 1A Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 0
(lse-f &i)el>rray(D, w) R 9K Te"
RedGal N B2
8ree"Gal N B2
!lueGal N B2

(lse-f &i)el>rray(D, w) R K0 Te"
RedGal N A9
8ree"Gal N A9
!lueGal N A9
(lse-f &i)el>rray(D, w) R 112 Te"
RedGal N @A
8ree"Gal N @A
!lueGal N @A
(lse-f &i)el>rray(D, w) R 199 Te"
RedGal N 12K
8ree"Gal N 12K
!lueGal N 12K
(lse-f &i)el>rray(D, w) R 1*A Te"
RedGal N 1A0
8ree"Gal N 1A0
!lueGal N 1A0
(lse-f &i)el>rray(D, w) R 20K Te"
RedGal N 1@2
8ree"Gal N 1@2
!lueGal N 1@2
(lse-f &i)el>rray(D, w) R 290 Te"
RedGal N 229
8ree"Gal N 229
!lueGal N 229
(lse-f &i)el>rray(D, w) IN 290 Te"
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 2HH
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap:::(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or quasi+co"tour dia%ram wit 1* 'a"ds of @
' sades of %ray, from 'lac1 to wite to 'lac1
=im D >s -"te%er, w >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

-f &i)el>rray(D, w) R K Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 0
(lse-f &i)el>rray(D, w) R 29 Te"
RedGal N B2
8ree"Gal N B2
!lueGal N B2

(lse-f &i)el>rray(D, w) R 90 Te"
RedGal N A9
8ree"Gal N A9
!lueGal N A9
(lse-f &i)el>rray(D, w) R HA Te"
RedGal N @A
8ree"Gal N @A
!lueGal N @A
(lse-f &i)el>rray(D, w) R *2 Te"
RedGal N 12K
8ree"Gal N 12K
!lueGal N 12K
(lse-f &i)el>rray(D, w) R KK Te"
RedGal N 1A0
8ree"Gal N 1A0
!lueGal N 1A0
(lse-f &i)el>rray(D, w) R 109 Te"
RedGal N 1@2
8ree"Gal N 1@2
!lueGal N 1@2
(lse-f &i)el>rray(D, w) R 120 Te"
RedGal N 229
8ree"Gal N 229
!lueGal N 229
(lse-f &i)el>rray(D, w) R 1BA Te"
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 2HH
(lse-f &i)el>rray(D, w) R 1H2 Te"
RedGal N 229
8ree"Gal N 229
!lueGal N 229
(lse-f &i)el>rray(D, w) R 1AK Te"
RedGal N 1@2
8ree"Gal N 1@2
!lueGal N 1@2
(lse-f &i)el>rray(D, w) R 1K9 Te"
RedGal N 1A0
8ree"Gal N 1A0
!lueGal N 1A0
(lse-f &i)el>rray(D, w) R 200 Te"
RedGal N 12K
8ree"Gal N 12K
!lueGal N 12K
(lse-f &i)el>rray(D, w) R 21A Te"
RedGal N @A
8ree"Gal N @A
!lueGal N @A
(lse-f &i)el>rray(D, w) R 2B2 Te"
RedGal N A9
8ree"Gal N A9
!lueGal N A9
(lse-f &i)el>rray(D, w) R 29K Te"
RedGal N B2
8ree"Gal N B2
!lueGal N B2
(lse
RedGal N 0
8ree"Gal N 0
!lueGal N 0
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap*(Ma) >s -"te%er, Q
wMa) >s -"te%er, &> >s Garia"t)
' 0or a co"ti"uously ca"%i"%, multicolor ma&<
' &i)el>rray(D, w) a''reviated to &>(D, w)
=im D >s -"te%er, w >s -"te%er, RedGal >s Lo"%
=im 8ree"Gal >s Lo"%, !lueGal >s Lo"%
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

-f &>(D, w) R 1A Te"
RedGal N -"t(A0 J 2.92 * (&>(D, w) + 9) Q
J 0 * ((&>(D, w) + 9) ; 2) Q
J 0.000H2B * ((&>(D, w) + 9) ; B))
8ree"Gal N -"t(H + 0.00BB2B * (&>(D, w) + 9) Q
J 0 * ((&>(D, w) + 9) ; 2) Q
J 0.00002B1 * ((&>(D, w) + 9) ; B))
!lueGal N -"t(@0 J 2.0@* * (&>(D, w) + 9) Q
J 0 * ((&>(D, w) + 9) ; 2) Q
J 0.002K * ((&>(D, w) + 9) ; B))

(lse-f &>(D, w) R B2 Te"
RedGal N -"t(@0 J 2.AH * (&>(D, w) + 1A) Q
J 0.01@1 * ((&>(D, w) + 1A) ; 2) Q
+ 0.000HAA * ((&>(D, w) + 1A) ; B))
8ree"Gal N -"t(H J 0.00AAH * (&>(D, w) + 1A) Q
J 0.00KB1 * ((&>(D, w) + 1A) ; 2) Q
+ 0.0000**@ * ((&>(D, w) + 1A) ; B))
!lueGal N -"t(120 J B.B0A * (&>(D, w) + 1A) Q
J 0.101 * ((&>(D, w) + 1A) ; 2) Q
+ 0.00@9H * ((&>(D, w) + 1A) ; B))
(lse-f &>(D, w) R 9K Te"
RedGal N -"t(1BH J 2.KB * (&>(D, w) + B2) Q
+ 0.00K1 * ((&>(D, w) + B2) ; 2) Q
J 0.00099* * ((&>(D, w) + B2) ; B))
8ree"Gal N -"t(H + 0.02AA * (&>(D, w) + B2) Q
+ 0.002@1 * ((&>(D, w) + B2) ; 2) Q
J 0.0002KA * ((&>(D, w) + B2) ; B))
!lueGal N -"t(1A0 + 0.*2A * (&>(D, w) + B2) Q
+ 0.BHB * ((&>(D, w) + B2) ; 2) Q
J 0.00*K * ((&>(D, w) + B2) ; B))
(lse-f &>(D, w) R A9 Te"
RedGal N -"t(1K0 J 2.@1 * (&>(D, w) + 9K) Q
J 0.01B9 * ((&>(D, w) + 9K) ; 2) Q
+ 0.00122 * ((&>(D, w) + 9K) ; B))
8ree"Gal N -"t(H J 0.0@@* * (&>(D, w) + 9K) Q
J 0.010K * ((&>(D, w) + 9K) ; 2) Q
J 0.001BK * ((&>(D, w) + 9K) ; B))
!lueGal N -"t(@0 + A.02K * (&>(D, w) + 9K) Q
J 0.021H * ((&>(D, w) + 9K) ; 2) Q
J 0.00BK@B * ((&>(D, w) + 9K) ; B))
(lse-f &>(D, w) R K0 Te"
RedGal N -"t(22H J 2.9 * (&>(D, w) + A9) Q
+ 0.09HB * ((&>(D, w) + A9) ; 2) Q
+ 0.000992 * ((&>(D, w) + A9) ; B))
8ree"Gal N -"t(1H J 1.H0B * (&>(D, w) + A9) Q
J 0.0*A@ * ((&>(D, w) + A9) ; 2) Q
J 0.0012@ * ((&>(D, w) + A9) ; B))
!lueGal N -"t(1H + 2.BH1 * (&>(D, w) + A9) Q
J 0.20K * ((&>(D, w) + A9) ; 2) Q
+ 0.00H0A * ((&>(D, w) + A9) ; B))
(lse-f &>(D, w) R @A Te"
RedGal N -"t(2H0 J 0.A11 * (&>(D, w) + K0) Q
+ 0.0AAH * ((&>(D, w) + K0) ; 2) Q
J 0.001** * ((&>(D, w) + K0) ; B))
8ree"Gal N -"t(A9 J 9.H@1 * (&>(D, w) + K0) Q
J 0.1B@ * ((&>(D, w) + K0) ; 2) Q
+ 0.009H* * ((&>(D, w) + K0) ; B))
!lueGal N -"t(10 J 0.9B0* * (&>(D, w) + K0) Q
+ 0.0B9H * ((&>(D, w) + K0) ; 2) Q
J 0.001A@ * ((&>(D, w) + K0) ; B))
(lse-f &>(D, w) R 112 Te"
RedGal N -"t(2H0 + 0.1HK * (&>(D, w) + @A) Q
J 0.01KH * ((&>(D, w) + @A) ; 2) Q
+ 0.000HBA * ((&>(D, w) + @A) ; B))
8ree"Gal N -"t(1A0 J H.K*@ * (&>(D, w) + @A) Q
+ 0.0K0A * ((&>(D, w) + @A) ; 2) Q
+ 0.000KBH * ((&>(D, w) + @A) ; B))
!lueGal N -"t(1H J 0.A2K * (&>(D, w) + @A) Q
J 0.09AK * ((&>(D, w) + @A) ; 2) Q
J 0.00B1* * ((&>(D, w) + @A) ; B))
(lse-f &>(D, w) R 12K Te"
RedGal N -"t(2H0 J 0.020AB * (&>(D, w) + 112) Q
+ 0.00*2@ * ((&>(D, w) + 112) ; 2) Q
+ 0.009H1 * ((&>(D, w) + 112) ; B))
8ree"Gal N -"t(2B0 J 2.AH* * (&>(D, w) + 112) Q
+ 0.121 * ((&>(D, w) + 112) ; 2) Q
J 0.0020H * ((&>(D, w) + 112) ; B))
!lueGal N -"t(H0 J 9.HH* * (&>(D, w) + 112) Q
J 0.1@@ * ((&>(D, w) + 112) ; 2) Q
+ 0.01B1 * ((&>(D, w) + 112) ; B))
(lse-f &>(D, w) R 199 Te"
RedGal N -"t(2B0 + B.A*H * (&>(D, w) + 12K) Q
+ 0.229 * ((&>(D, w) + 12K) ; 2) Q
J 0.00B9B * ((&>(D, w) + 12K) ; B))
8ree"Gal N -"t(2H0 J 0.BA*@ * (&>(D, w) + 12K) Q
+ 0.022B * ((&>(D, w) + 12K) ; 2) Q
+ 0.000091B * ((&>(D, w) + 12K) ; B))
!lueGal N -"t(120 J 0.KB02 * (&>(D, w) + 12K) Q
+ 0.9B2 * ((&>(D, w) + 12K) ; 2) Q
J 0.00@0@ * ((&>(D, w) + 12K) ; B))

(lse-f &>(D, w) R 1A0 Te"
RedGal N -"t(12K + K.1@* * (&>(D, w) + 199) Q
+ 0.0H@ * ((&>(D, w) + 199) ; 2) Q
J 0.00K12 * ((&>(D, w) + 199) ; B))
8ree"Gal N -"t(2H0 + 0.B*K9 * (&>(D, w) + 199) Q
+ 0.029B * ((&>(D, w) + 199) ; 2) Q
+ 0.001K@ * ((&>(D, w) + 199) ; B))
!lueGal N -"t(A0 + A.00B * (&>(D, w) + 199) Q
J 0.009AB * ((&>(D, w) + 199) ; 2) Q
J 0.01B9 * ((&>(D, w) + 199) ; B))

(lse-f &>(D, w) R 1*A Te"
RedGal N -"t(1H + B.K9@ * (&>(D, w) + 1A0) Q
J 0.BB1 * ((&>(D, w) + 1A0) ; 2) Q
+ 0.00K0K * ((&>(D, w) + 1A0) ; B))
8ree"Gal N -"t(2B0 + 2.A09 * (&>(D, w) + 1A0) Q
+ 0.11H * ((&>(D, w) + 1A0) ; 2) Q
J 0.0002H* * ((&>(D, w) + 1A0) ; B))
!lueGal N -"t(20 J 9.9B2 * (&>(D, w) + 1A0) Q
J 0.A9K * ((&>(D, w) + 1A0) ; 2) Q
+ 0.0212 * ((&>(D, w) + 1A0) ; B))
(lse-f &>(D, w) R 1@2 Te"
RedGal N -"t(H J 0.H2@ * (&>(D, w) + 1*A) Q
+ 0.0H*2 * ((&>(D, w) + 1*A) ; 2) Q
J 0.001H1 * ((&>(D, w) + 1*A) ; B))
8ree"Gal N -"t(1A0 + A.0K * (&>(D, w) + 1*A) Q
+ 0.102 * ((&>(D, w) + 1*A) ; 2) Q
J 0.00H*9 * ((&>(D, w) + 1*A) ; B))
!lueGal N -"t(1*0 J K.@ * (&>(D, w) + 1*A) Q
+ 0.BAK * ((&>(D, w) + 1*A) ; 2) Q
J 0.00AB2 * ((&>(D, w) + 1*A) ; B))
(lse-f &>(D, w) R 20K Te"
RedGal N -"t(H + 0.192 * (&>(D, w) + 1@2) Q
J 0.01HB * ((&>(D, w) + 1@2) ; 2) Q
+ 0.000B@@ * ((&>(D, w) + 1@2) ; B))
8ree"Gal N -"t(A0 + 9.@H1 * (&>(D, w) + 1@2) Q
J 0.1*B * ((&>(D, w) + 1@2) ; 2) Q
+ 0.0029A * ((&>(D, w) + 1@2) ; B))
!lueGal N -"t(299 J 1.@A@ * (&>(D, w) + 1@2) Q
+ 0.0A9K * ((&>(D, w) + 1@2) ; 2) Q
+ 0.00AB9 * ((&>(D, w) + 1@2) ; B))
(lse-f &>(D, w) R 229 Te"
RedGal N -"t(H J 0.090B * (&>(D, w) + 20K) Q
+ 0.00BKA * ((&>(D, w) + 20K) ; 2) Q
J 0.001B * ((&>(D, w) + 20K) ; B))
8ree"Gal N -"t(1H + 1.B0B * (&>(D, w) + 20K) Q
J 0.0HH * ((&>(D, w) + 20K) ; 2) Q
+ 0.000*@1 * ((&>(D, w) + 20K) ; B))
!lueGal N -"t(299 + 2.@02 * (&>(D, w) + 20K) Q
+ 0.29 * ((&>(D, w) + 20K) ; 2) Q
J 0.00HK1 * ((&>(D, w) + 20K) ; B))
(lse-f &>(D, w) R 290 Te"
RedGal N -"t(10 J 0.@1KA * (&>(D, w) + 229) Q
J 0.0HKA * ((&>(D, w) + 229) ; 2) Q
+ 0.009K2 * ((&>(D, w) + 229) ; B))
8ree"Gal N -"t(H + 0.19@9 * (&>(D, w) + 229) Q
J 0.01*1 * ((&>(D, w) + 229) ; 2) Q
+ 0.0009K9 * ((&>(D, w) + 229) ; B))
!lueGal N -"t(1A0 + A.11 * (&>(D, w) + 229) Q
J 0.0B@2 * ((&>(D, w) + 229) ; 2) Q
+ 0.00B * ((&>(D, w) + 229) ; B))
(lse-f &>(D, w) IN 290 Te"
RedGal N -"t(20 + 0.@02 * (&>(D, w) + 290) Q
+ 0.1*B * ((&>(D, w) + 290) ; 2) Q
J 0.01B@ * ((&>(D, w) + 290) ; B))
8ree"Gal N -"t(H J 0.02HH9 * (&>(D, w) + 290) Q
+ 0.00A19 * ((&>(D, w) + 290) ; 2) Q
J 0.000BH* * ((&>(D, w) + 290) ; B))
!lueGal N -"t(A0 + *.1H* * (&>(D, w) + 290) Q
+ 0.10H * ((&>(D, w) + 290) ; 2) Q
J 0.02@K * ((&>(D, w) + 290) ; B))
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap**(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a quasi+co"tour dia%ram usi"% @ differe"t colors
=im D >s -"te%er, w >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1
' =ar1 'row"6
-f &i)el>rray(D, w) R 1A Te"
RedGal N 100
8ree"Gal N 0
!lueGal N H0
' !row"6
(lse-f &i)el>rray(D, w) R 9K Te"
RedGal N 1H0
8ree"Gal N 0
!lueGal N 90
' Red6
(lse-f &i)el>rray(D, w) R K0 Te"
RedGal N 2HH
8ree"Gal N 0
!lueGal N 0
' 2ra"%e6
(lse-f &i)el>rray(D, w) R 112 Te"
RedGal N 2HH
8ree"Gal N 12K
!lueGal N 0
' Eellow6
(lse-f &i)el>rray(D, w) R 199 Te"
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 0
' 8ree"6
(lse-f &i)el>rray(D, w) R 1*A Te"
RedGal N 0
8ree"Gal N 2HH
!lueGal N 0
' Li%t 'lue6
(lse-f &i)el>rray(D, w) R 20K Te"
RedGal N 0
8ree"Gal N 2HH
!lueGal N 2HH
' !lue6
(lse-f &i)el>rray(D, w) R 290 Te"
RedGal N 0
8ree"Gal N 20
!lueGal N 2HH
' Giolet6
(lse
RedGal N 20
8ree"Gal N 0
!lueGal N 1H0
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap***(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a quasi+co"tour dia%ram usi"% @ differe"t colors
=im D >s -"te%er, w >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1
' :ear 'lac1
-f &i)el>rray(D, w) R K Te"
RedGal N A0
8ree"Gal N 0
!lueGal N @0
' =ar1 Giolet6
(lse-f &i)el>rray(D, w) R 29 Te"
RedGal N @0
8ree"Gal N 0
!lueGal N 120
' Giolet6
(lse-f &i)el>rray(D, w) R 90 Te"
RedGal N 120
8ree"Gal N 0
!lueGal N 1A0
' =ar1 red
(lse-f &i)el>rray(D, w) R HA Te"
RedGal N 1K0
8ree"Gal N 0
!lueGal N @0
' Red6
(lse-f &i)el>rray(D, w) R *2 Te"
RedGal N 2HH
8ree"Gal N 0
!lueGal N 0
' =ar1 2ra"%e6
(lse-f &i)el>rray(D, w) R KK Te"
RedGal N 2HH
8ree"Gal N A9
!lueGal N 0
' 2ra"%e6
(lse-f &i)el>rray(D, w) R 109 Te"
RedGal N 2HH
8ree"Gal N 12K
!lueGal N 0
' Eellow6
(lse-f &i)el>rray(D, w) R 120 Te"
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 0
' Li%t yellow6
(lse-f &i)el>rray(D, w) R 1BA Te"
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 12K
' Li%t %ree"6
(lse-f &i)el>rray(D, w) R 1H2 Te"
RedGal N 12K
8ree"Gal N 2HH
!lueGal N 12K
' 8ree"6
(lse-f &i)el>rray(D, w) R 1AK Te"
RedGal N 0
8ree"Gal N 2HH
!lueGal N 0
' !lue+%ree"6
(lse-f &i)el>rray(D, w) R 1K9 Te"
RedGal N 0
8ree"Gal N 1A0
!lueGal N 1A0
' Li%t 'lue6
(lse-f &i)el>rray(D, w) R 200 Te"
RedGal N 0
8ree"Gal N A0
!lueGal N 2HH
' !lue6
(lse-f &i)el>rray(D, w) R 21A Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 2HH
' =ar1 'lue6
(lse-f &i)el>rray(D, w) R 2B2 Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 1K0
' !lue+'lac16
(lse-f &i)el>rray(D, w) R 29K Te"
RedGal N 20
8ree"Gal N 0
!lueGal N 120
' :ear 'lac16
(lse
RedGal N 1H
8ree"Gal N 0
!lueGal N A0
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap;(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a ma& wit co"ti"uous colors, from 'row"
' trou% red, ora"%e a"d yellow to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

' from 'lac1 to red
-f &i)el>rray(D, w) R A9 Te"
RedGal N -"t(9 * &i)el>rray(D, w))
8ree"Gal N 0
!lueGal N 0
' from red to ora"%e
(lse-f &i)el>rray(D, w) R 12K Te"
RedGal N 2HH
8ree"Gal N -"t(2 * (&i)el>rray(D, w) + A9))
!lueGal N 0
' from ora"%e to yellow
(lse-f &i)el>rray(D, w) R 1@2 Te"
RedGal N 2HH
8ree"Gal N -"t(2 * (&i)el>rray(D, w) + A9))
!lueGal N 0
' from yellow to wite
(lse
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N -"t(9 * (&i)el>rray(D, w) + 1@2))

("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap;;(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a quasi+co"tour ma& wit colors from 'row"
' trou% red, ora"%e a"d yellow to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1
' 'lac16
-f &i)el>rray(D, w) R 1A Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 0
' dar1 'row"6
(lse-f &i)el>rray(D, w) R 9K Te"
RedGal N K0
8ree"Gal N 0
!lueGal N 0
' 'row"6
(lse-f &i)el>rray(D, w) R K0 Te"
RedGal N 1A0
8ree"Gal N 0
!lueGal N 0
' red6
(lse-f &i)el>rray(D, w) R 112 Te"
RedGal N 2HH
8ree"Gal N 0
!lueGal N 0
' dar1 ora"%e6
(lse-f &i)el>rray(D, w) R 199 Te"
RedGal N 2HH
8ree"Gal N A9
!lueGal N 0
' dar1 ora"%e6
(lse-f &i)el>rray(D, w) R 1*A Te"
RedGal N 2HH
8ree"Gal N @A
!lueGal N 0
' ora"%e6
(lse-f &i)el>rray(D, w) R 20K Te"
RedGal N 2HH
8ree"Gal N 199
!lueGal N 0
' Eellow6
(lse-f &i)el>rray(D, w) R 290 Te"
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 0
' li%t yellow6
(lse
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 12K
("d -f

$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap;;;(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a quasi+co"tour ma& wit colors from 'row"
' trou% red, ora"%e a"d yellow to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1
' 'lac16
-f &i)el>rray(D, w) R K Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 0
' dar1 'row"6
(lse-f &i)el>rray(D, w) R 29 Te"
RedGal N K0
8ree"Gal N 0
!lueGal N 0
' 'row"6
(lse-f &i)el>rray(D, w) R 90 Te"
RedGal N 120
8ree"Gal N 0
!lueGal N 0
' dar1 red6
(lse-f &i)el>rray(D, w) R HA Te"
RedGal N 1@2
8ree"Gal N 0
!lueGal N 0
' red6
(lse-f &i)el>rray(D, w) R *2 Te"
RedGal N 2HH
8ree"Gal N 0
!lueGal N 0
' dar1 ora"%e6
(lse-f &i)el>rray(D, w) R KK Te"
RedGal N 2HH
8ree"Gal N A9
!lueGal N 0
' ora"%e6
(lse-f &i)el>rray(D, w) R 109 Te"
RedGal N 2HH
8ree"Gal N 12K
!lueGal N 0
' li%t ora"%e6
(lse-f &i)el>rray(D, w) R 120 Te"
RedGal N 2HH
8ree"Gal N 1@2
!lueGal N 0
' yellow6
(lse-f &i)el>rray(D, w) R 1BA Te"
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N 0
' li%t ora"%e6
(lse-f &i)el>rray(D, w) R 1H2 Te"
RedGal N 2HH
8ree"Gal N 1@2
!lueGal N 0
' ora"%e6
(lse-f &i)el>rray(D, w) R 1AK Te"
RedGal N 2HH
8ree"Gal N 12K
!lueGal N 0
' dar1 ora"%e6
(lse-f &i)el>rray(D, w) R 1K9 Te"
RedGal N 2HH
8ree"Gal N A9
!lueGal N 0
' red6
(lse-f &i)el>rray(D, w) R 200 Te"
RedGal N 2HH
8ree"Gal N 0
!lueGal N 0
' dar1 red6
(lse-f &i)el>rray(D, w) R 21A Te"
RedGal N 1@2
8ree"Gal N 0
!lueGal N 0
' 'row"6
(lse-f &i)el>rray(D, w) R 2B2 Te"
RedGal N 120
8ree"Gal N 0
!lueGal N 0
' dar1 'row"6
(lse-f &i)el>rray(D, w) R 29K Te"
RedGal N K0
8ree"Gal N 0
!lueGal N 0
' 'lac16
(lse
RedGal N 0
8ree"Gal N 0
!lueGal N 0
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap+(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a ma& wit co"ti"uous colors,
' from 'lac1 trou% 'lue to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

' from 'lac1 to dar1 'lue
-f &i)el>rray(D, w) R A9 Te"
RedGal N 0
8ree"Gal N 0
!lueGal N -"t(9 * &i)el>rray(D, w))
' from dar1 'lue to li%t 'lue
(lse-f &i)el>rray(D, w) R 1@2 Te"
RedGal N 0
8ree"Gal N -"t(2 * (&i)el>rray(D, w) + A9))
!lueGal N 2HH
' from li%t 'lue to wite
(lse
RedGal N -"t(9 * (&i)el>rray(D, w) + 1@2))
8ree"Gal N 2HH
!lueGal N 2HH

("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap++(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a quasi+co"tour ma& wit @ colors,
' from 'lac1 trou% 'lue to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1
' 'lac16
-f &i)el>rray(D, w) R 1A Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 0
' very dar1 'lue6
(lse-f &i)el>rray(D, w) R 9K Te"
RedGal N 0
8ree"Gal N 0
!lueGal N K0
' dar1 'lue6
(lse-f &i)el>rray(D, w) R K0 Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 1A0
' 'lue
(lse-f &i)el>rray(D, w) R 112 Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 2HH
' %ray+'lue
(lse-f &i)el>rray(D, w) R 199 Te"
RedGal N 0
8ree"Gal N A9
!lueGal N 2HH
' li%t %ray+'lue
(lse-f &i)el>rray(D, w) R 1*A Te"
RedGal N 0
8ree"Gal N 1H9
!lueGal N 2HH
' dar1 %ree"+'lue
(lse-f &i)el>rray(D, w) R 20K Te"
RedGal N A9
8ree"Gal N 1@A
!lueGal N 2HH
' %ree"+'lue
(lse-f &i)el>rray(D, w) R 290 Te"
RedGal N A9
8ree"Gal N 2HH
!lueGal N 2HH
' li%t %ree"+'lue
(lse
RedGal N 12K
8ree"Gal N 2HH
!lueGal N 2HH
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap+++(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a quasi+co"tour ma& wit 1* 'a"ds usi"% @ colors,
' from 'lac1 trou% 'lue to li%t 'lue a"d 'ac1
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

' 'lac1
-f &i)el>rray(D, w) R K Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 0
' 'lue+'lac1
(lse-f &i)el>rray(D, w) R 29 Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 1A0
' dar1 'lue
(lse-f &i)el>rray(D, w) R 90 Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 2HH
' 'lue
(lse-f &i)el>rray(D, w) R HA Te"
RedGal N 0
8ree"Gal N 9K
!lueGal N 2HH
' %ray+'lue
(lse-f &i)el>rray(D, w) R *2 Te"
RedGal N 0
8ree"Gal N @A
!lueGal N 2HH
' li%t %ray+'lue
(lse-f &i)el>rray(D, w) R KK Te"
RedGal N 0
8ree"Gal N 1H9
!lueGal N 2HH
' dar1 %ree"+'lue
(lse-f &i)el>rray(D, w) R 109 Te"
RedGal N A9
8ree"Gal N 1@A
!lueGal N 2HH
' %ree"+'lue
(lse-f &i)el>rray(D, w) R 120 Te"
RedGal N A9
8ree"Gal N 2HH
!lueGal N 2HH
' li%t %ree"+'lue
(lse-f &i)el>rray(D, w) R 1BA Te"
RedGal N 12K
8ree"Gal N 2HH
!lueGal N 2HH
' %ree"+'lue
(lse-f &i)el>rray(D, w) R 1H2 Te"
RedGal N A9
8ree"Gal N 2HH
!lueGal N 2HH
' dar1 %ree"+'lue
(lse-f &i)el>rray(D, w) R 1AK Te"
RedGal N A9
8ree"Gal N 1@A
!lueGal N 2HH
' li%t %ray+'lue
(lse-f &i)el>rray(D, w) R 1K9 Te"
RedGal N 0
8ree"Gal N 1H9
!lueGal N 2HH
' %ray+'lue
(lse-f &i)el>rray(D, w) R 200 Te"
RedGal N 0
8ree"Gal N @A
!lueGal N 2HH
' 'lue
(lse-f &i)el>rray(D, w) R 21A Te"
RedGal N 0
8ree"Gal N 9K
!lueGal N 2HH
' dar1 'lue
(lse-f &i)el>rray(D, w) R 2B2 Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 2HH
' dar1 'lue
(lse-f &i)el>rray(D, w) R 29K Te"
RedGal N 0
8ree"Gal N 0
!lueGal N 1A0
' 'lac1
(lse
RedGal N 0
8ree"Gal N 0
!lueGal N 0
("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMap<(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a ma& wit co"ti"uous colors,
' from 'lac1 trou% 'lue to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

' from 'lac1 to dar1 %ree"
-f &i)el>rray(D, w) R A9 Te"
RedGal N 0
8ree"Gal N 12K J -"t(2 * &i)el>rray(D, w))
!lueGal N 12K + -"t(2 * &i)el>rray(D, w))
' from dar1 %ree" to yellow
(lse-f &i)el>rray(D, w) R 1@2 Te"
RedGal N -"t(2 * (&i)el>rray(D, w) + A9))
8ree"Gal N 2HH
!lueGal N 0
' from yellow to wite
(lse
RedGal N 2HH
8ree"Gal N 2HH
!lueGal N -"t(B * (&i)el>rray(D, w) + 1@2))

("d -f
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& BitMapR"B(Ma) >s -"te%er, Q
wMa) >s -"te%er, &i)el>rray >s Garia"t)
' 0or a ma& wit co"ti"uous colors,
' from 'lac1 trou% 'lue to wite
=im D >s -"te%er, w >s -"te%er, RedGal >s -"te%er
=im 8ree"Gal >s -"te%er, !lueGal >s -"te%er
0or D N Ma) To 0 #te& +1
0or w N 0 To wMa) + 1

RedGal N -"t(Red(&i)el>rray(D, w)))
8ree"Gal N -"t(8ree"(&i)el>rray(D, w)))
!lueGal N -"t(!lue(&i)el>rray(D, w)))
$rite>3i)el RedGal Mod 2HA, 8ree"Gal Mod 2HA, Q
!lueGal Mod 2HA
:e)t w
' =o "ot ca"%e te followi"%, esse"tial row &addi"%
w N wMa) * B
=o $ile (w Mod 9) RI 0
$rite>!yte 0
w N w J 1
Loo&
:e)t D

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& !riteA!ord(!yGal $ordGalue >s -"te%er)

' $rite a two 'yte sort word to te 'i"ary data stream.
=im 2ut&ut0ile:um'er >s -"te%er
2ut&ut0ile:um'er N 1
3ut ]2ut&ut0ile:um'er, , $ordGalue
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& !riteALong(!yGal Lo"%Galue >s Lo"%)
' $rite a four+'yte lo"% word to te 'i"ary data stream.
=im 2ut&ut0ile:um'er >s -"te%er
2ut&ut0ile:um'er N 1
3ut ]2ut&ut0ile:um'er, , Lo"%Galue
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& !riteAPi0el(!yGal RedGalue >s !yte, Q
!yGal 8ree"Galue >s !yte, !yGal !lueGalue >s !yte)
' $rite a tree+'yte &i)el color value to
' te 'i"ary data stream. :ote tat tere is
' "o &addi"% u& to a word or lo"% 'ou"dary.
=im 2ut&ut0ile:um'er >s -"te%er
2ut&ut0ile:um'er N 1
3ut ]2ut&ut0ile:um'er, , !lueGalue
3ut ]2ut&ut0ile:um'er, , 8ree"Galue
3ut ]2ut&ut0ile:um'er, , RedGalue
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Pri%ate Su& !riteAByte(!yGal !yteGalue >s !yte)

' $rite a 'yte.
=im 2ut&ut0ile:um'er >s -"te%er
2ut&ut0ile:um'er N 1
3ut ]2ut&ut0ile:um'er, , !yteGalue
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''************************''''''''''''''''''
'''''''''''''''''* *''''''''''''''''''
'''''''''''''''''* ScanF *''''''''''''''''''
'''''''''''''''''* *''''''''''''''''''
'''''''''''''''''************************''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tis su'routi"e &lots a" array of values of a fu"ctio" 0
' were 0 de&e"ds o" two &arameters, ) a"d y, wose values
' are s&ecified i" "umerical a)es o" te s&readseet.
'
' 0or e)am&le, te fu"ctio" 0 ca" 'e te sum of squares of
' te residuals ##R of te com&ariso" of a" e)&erime"tal
' data set wit tose of a "umerical simulatio", a"d te
' )+ a"d y+values two coefficie"ts determi"i"% ##R. -" tat
' case, te macro will com&ute values tat ca" su'seque"tly
' 'e dis&layed 'y Ma&&er as a" error surface a"d, wit
' #ca"01, 'e im&orted i"to #imo"Luca #a"toro's macro -soL.
'
' Te macro wor1s 'y ca"%i"% te s&readseet &arameters )
' a"d y 'y i"vasive sam&li"%, readi"% te corres&o"di"%
' results as array eleme"ts. Te &arameter values must 'e
' s&ecified i" te M+ a"d E+a)es of te array.
'
' Te su'routi"e is called 'y two small driver macros tat
' set te i"te%er &arameter L to eiter 0 or 1. $e" L is
' set to 0 te su'routi"e merely fills te )y array wit
' te requested values of eiter lo% 0 or 0. $e" L N 1 te
' macro also Lists tese 0+values i" te i"&ut format for
' #imo"Luca #a"toro's macro -soL for %e"erati"% co"tour
' dia%rams, at a locatio" s&ecified 'y te user. Tis is a
' lo"% list, wic will occu&y (4Ma)+1)times (RMa)+1) rows.
' Ma1e sure tere is e"ou% &lace for it, a"d it does"'t
' overwrite useful results.
' 3R24(=5R(6
'
' Leave two em&ty cells, o"e 'elow te oter, at te to&
' left cor"er of te s&ace for te ME &lot. Te to& cell
' will 'ecome te macro la'el, te 'ottom te a"cor cell
' of te ME &lot. To te ri%t of te a"cor cell, &ut te
' la'els of te M+a)is, a"d 'elow te a"cor cell, te
' la'els for te E+a)is. Tese two sets of la'els defi"e
' te s&ecific )+ a"d y+values for wic 0 will 'e evaluated
' a"d te result &laced i" te a&&ro&riate cell of te ME
' array.
'
' Te macro reads te values of te M+ a"d E a)es, su'sti+
' tutes tem for ) a"d y res&ectively, te" fills te ME
' array wit te resulti"% values of 0.
'
' Di%li%t te array area, i"cludi"% its a)es, a"d call
' te macro.
' 0or su'seque"t use of Ma&&er, eiter leave te a"cor
' left cell em&ty (so tat Ma&&er will autoscale), or &lace
' a 1 tere (i" wic case Ma&&er will as1 for mi"imum a"d
' ma)imum scale values). Te latter o&tio" is useful we"
' several ma&s sould ave te same color (or %ray) scales.
' (M>M3L(#6
' >(B sectio" 9.1* illustrates te use of #ca"0
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ScanF:() ' for com&uti"% ? out&utti"%
' te data array for 0(),y)
=im L >s -"te%er
L N 0
4all #ca"0(0)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ScanF*() ' for also com&uti"% ? out&utti"%
' a" -soList as i"&ut for -soL.)la
=im L >s -"te%er
L N 1
4all #ca"0(1)
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& ScanF(L)
=im 4 >s -"te%er, 4Ma) >s -"te%er, R >s Lo"%
=im RMa) >s Lo"%, RR >s Lo"%, RRMa) >s Lo"%
=im f0 >s Garia"t, -soList >s Garia"t, v0 >s Garia"t
=im fME >s Garia"t, vME >s Garia"t
=im a>, a>>, a0, aTL, aM, aE, !e%i", ("di"%
=im f0-"it, fM-"it, fE-"it, 3erce"ta%e, 3os4olo"
=im r%0 >s Ra"%e, r%L >s Ra"%e, r%TL >s Ra"%e, r%M >s Ra"%e
=im r%ME >s Ra"%e, r%MMEE >s Ra"%e, r%E >s Ra"%e
4Ma) N 0
RMa) N 0
!e%i"6
4Ma) N #electio".4olum"s.4ou"t
RMa) N #electio".Rows.4ou"t
#et r%ME N Ra"%e(#electio".>ddress)
RR N 0
' -f area is "ot i%li%ted 'efore te macro is called
-f 4Ma) R 2 >"d RMa) R 2 Te"
>"swer N Ms%!o)(PEou for%ot to i%li%tP Q
? 4r(1B) ? Pte 'loc1 of i"&ut data.P Q
? 4r(1B) ? P=o you wa"t to do so "owOP Q
, v'Ees:o)
-f >"swer N v':o Te" ("d
-f >"swer N v'Ees Te"
#et r%ME N >&&licatio".-"&ut!o)(3rom&t6N Q
PTe i"&ut data are located i"6P, Ty&e6NK)
r%ME.#elect
("d -f
8oTo !e%i"
("d -f
RRMa) N (4Ma) + 1) * (RMa) + 1)
Re=im -soList(1 To RRMa), 1 To B) >s =ou'le
' 4o&y te values of te M+ a"d E+a)es
Re=im v0(1 To RMa), 1 To 4Ma))
Re=im vME(1 To RMa) + 1, 1 To 4Ma) + 1)
0or 4 N 1 To 4Ma)
0or R N 1 To RMa)
v0(R, 4) N #electio"(R, 4).Galue
:e)t R
:e)t 4
' Read te values of M a"d E, a"d save teir %e"erati"%
' formulas for restoratio" we" tis macro is do"e
#et r%M N >&&licatio".-"&ut!o)(3rom&t6NPMP, Q
Title6NP#ca"0P ? L, Ty&e6NK)
r%M.#elect
aM N #electio".>ddress
fM-"it N #electio".0ormula
#et r%E N >&&licatio".-"&ut!o)(3rom&t6NPEP, Q
Title6NP#ca"0P ? L, Ty&e6NK)
r%E.#elect
aE N #electio".>ddress
fE-"it N #electio".0ormula
' Read te address of te fu"ctio" 0
' tat sould 'e &laced i" te ME &lot
#et r%0 N >&&licatio".-"&ut!o)(3rom&t6NP0P, Q
Title6NP#ca"0P ? L, Ty&e6NK)
r%0.#elect
a0 N #electio".>ddress
f0-"it N #electio".0ormula
-f L N 1 Te"
#et r%L N >&&licatio".-"&ut!o)(3rom&t6N Q
P3lace te to& left+a"d cell of te list ere6P, Q
Title6NP#ca"0P ? L, Ty&e6NK)
r%L.#elect
aL N #electio".>ddress
("d -f
' Lee& te user i"formed a'out
' te &ro%ress of te com&utatio"
>&&licatio".#tatus!ar N True
>&&licatio".#tatus!ar N PTe com&utatio" is P ? Q
P0[ com&lete.P

>&&licatio".#cree"5&dati"% N 0alse
' Read te values of 0 to 'e dis&layed i" te ME &lot
r%ME.#elect
a> N #electio".>ddress
#electio".2ffset(1, 1).#elect
#electio".Resi7e(RMa) + 1, 4Ma) + 1).#elect
a>> N #electio".>ddress
#et r%MMEE N Ra"%e(a>>)
r%MMEE.#elect
0or 4 N 2 To 4Ma)
0or R N 2 To RMa)
r%M.#elect
#electio".Galue N v0(1, 4)
r%E.#elect
#electio".Galue N v0(R, 1)
r%0.#elect
vME(R + 1, 4 + 1) N #electio".Galue
' -f a lo%aritmic scale is :2T desired (e.%., we" vME is
' "e%ative, &lace a" a&ostro&y i" fro"t of te "e)t li"e6
vME(R + 1, 4 + 1) N Lo%(vME(R + 1, 4 + 1)) C Lo%(10)
' to 'comme"t out' te &recedi"% li"e.

:e)t R
3erce"ta%e N H * -"t(20 * (4 C 4Ma)))
>&&licatio".#tatus!ar N PTe com&utatio" is P ? Q
3erce"ta%e ? P[ com&lete.P
:e)t 4
>&&licatio".#tatus!ar N 0alse
>&&licatio".#cree"5&dati"% N True
' =is&lay te out&ut results
r%MMEE.#elect
#electio".Galue N vME
' Reset te &arameter formulas
r%M.#elect
#electio".0ormula N fM-"it
r%E.#elect
#electio".0ormula N fE-"it
r%0.#elect
#electio".0ormula N f0-"it
' La'el te macro a"d add self+docume"tatio"
3os4olo" N -"#tr(1, a>, P6P)
aTL N Left(a>, 3os4olo" + 1)
#et r%TL N Ra"%e(aTL)
r%TL.#elect
#electio".2ffset(+1, 0).#elect
$it >ctive4ell
.Galue N P#ca"0P ? L
.0o"t.!old N True
.0o"t.-talic N 0alse
.0o"t.4olor-"de) N H
.Dori7o"tal>li%"me"t N )l4e"ter
.-"terior.4olor-"de) N 20
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.#a&e.$idt N 200
.4omme"t.#a&e.Dei%t N K0
.4omme"t.Te)t Te)t6NP#ca"0P ? L ? P versio" 10P ? Q
4r(10) ? 4r(10) ? P-"&ut6 P ? a> ? 4r(10) ? PM i" P ? Q
aM ? P wit i"itial formulaCvalue P ? fM-"it ? 4r(10) ? Q
PE i" P ? aE ? P wit i"itial formulaCvalue P ? Q
fE-"it ? 4r(10) ? P0 i" P ? a0 ? Q
P wit i"itial formula P ? f0-"it ? 4r(10) ? Q
Pdate N P ? =ate ? P, time N P ? Time
("d $it
-f L N 0 Te" 8oTo ("di"%
' Tis &art, used o"ly we" L N 1, &uts te same 0 values i" a
list
' suita'le for direct im&ortatio" i"to MMM #a"toro's -soL macro.
' Te list is %e"erated starti"% i" cell ->1 (as te default) or
a"y
' oter cell so desi%"ated 'y te user. Te i"&ut 'o) allowi"%
te user
' suc desi%"atio" also lists te le"%t of te list< its
' widt is fi)ed at tree cells. Te first colum" co"tai"s
' ), te seco"d y, a"d te tird te fu"ctio" 0(),y).
'
' Di%li%t a" array tree colum"s wide, a"d le"%t (RMa)J1)
' times (4Ma)J1), te" s&ecify te i"&ut array - i"cludi"%
' its M a"d E a)es, a"d e"ter wit 4trlJ#iftJ("ter.
0or 4 N 1 To 4Ma) + 1
0or R N 1 To RMa) + 1
RR N RR J 1
-soList(RR, 1) N v0(1, 4 J 1)
-soList(RR, 2) N v0(R J 1, 1)
-soList(RR, B) N vME(R, 4)
:e)t R
:e)t 4
' La'el a"d out&ut -soList
r%L.#elect
$it >ctive4ell
.4lear4omme"ts
.>dd4omme"t
.4omme"t.Gisi'le N 0alse
.4omme"t.#a&e.$idt N 1A0
.4omme"t.#a&e.Dei%t N 90
.4omme"t.Te)t Te)t6NP-soList wit #ca"01 Gersio" 10P ? Q
4r(10) ? 4r(10) ? Pdate N P ? =ate ? P, time N P ? Time
("d $it
r%L.Resi7e(RR, B).#elect
#electio" N -soList
("di"%6
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''********************************'''''''''''''
''''''''''''''* *'''''''''''''
''''''''''''''* RootFinder *'''''''''''''
''''''''''''''; ;''''''''''''''
''''''''''''''********************************'''''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tis macro fi"ds te real root of a fu"ctio" 0()) of a
' si"%le varia'le ) 'y 'isectio" i"side a user+defi"ed
' ra"%e. :ote6 'ecause te macro loo1s for a si%" ca"%e
' i" 0()), it will also fi"d si"%ularities, suc as wit
' ta"()) for ) N &iC2.
' Te value of te resolutio" criterio" 0Res ca" 'e ca"%ed
' de&e"di"% o" te requireme"ts of te &ro'lem. 0or sim&le
' fu"ctio"s, a i% resolutio" (i.e., a small value of
' 0Res, suc as 1(+12) may 'e desired, wile com&licated
' e)&ressio"s may require a lower resolutio". 0or fu"ctio"s
' tat reac values muc lar%er ta" 1, a relative rater
' ta" a" a'solute resolutio" may 'e more a&&ro&riate.
' #imilarly, te criterio" for decidi"% 'etwee" a root a"d
' a si"%ularity may ave to 'e ca"%ed for fu"ctio"s wit
' e)tremely stee& slo&es "ear teir roots.
' #5!R25T-:(#6
' Tis macro does "ot require a"y su'routi"es.
' -:35T6
' Te locatio"s of te fu"ctio" 0()) a"d te i"de&e"de"t
' varia'le ) must 'e i" colum"s of equal le"%t, a"d are
' e"tered i"to te macro via i"&ut 'o)es.
' Te &arameter ) must ca"%e mo"oto"ically (i.e., eiter
' asce"d or desce"d co"ti"uously) i" its colum", wile
' te fu"ctio" 0()) sould ave o"e a"d o"ly o"e 7ero
' crossi"% i" te selected colum" or colum" fra%me"t.
' Te &arameter ) ca" 'e a value or a fu"ctio" of some
' oter &arameters.
' -f te fu"ctio" o" te s&readseet e)i'its more ta" o"e
' 7ero crossi"%, restrict te si7e of te 'loc1 so tat it
' will co"tai" o"ly o"e of tem.
' 25T35T6
' Te root is dis&layed i" a messa%e 'o).
' 3R24(=5R(6
' 4all te macro, te" e"ter te colum" ra"%es for 0()) a"d
' ) i" te i"&ut 'o)es.
Su& RootFinder()
=im i >s -"te%er, : >s -"te%er
=im "c >s -"te%er, "r >s -"te%er
=im 00irst >s =ou'le, 0Last >s =ou'le, 0:ew >s =ou'le
=im 0Res >s =ou'le, Ratio >s =ou'le
=im M0irst >s =ou'le, MLast >s =ou'le, M:ew >s =ou'le
=im 00ormula >s Garia"t, 0Galue >s Garia"t
=im M0ormula >s Garia"t, MGalue >s Garia"t
=im 00ormula#ave >s Garia"t, M0ormula#ave >s Garia"t
=im 0Ra"%e >s Ra"%e, MRa"%e >s Ra"%e
=im 03rom&t, M3rom&t, 0Title, MTitle
' -"&ut te fu"ctio" 0()) a"d its associated files
03rom&t N PTe fu"ctio" 0()) is i" colum"6P
0Title N PRoot0i"der6 -"&ut 0())P
#et 0Ra"%e N >&&licatio".-"&ut!o)(03rom&t, 0Title, Ty&e6NK)
0Ra"%e.#elect
00ormula N #electio".0ormula
0Galue N #electio".Galue
00ormula#ave N #electio".0ormula
' Test te 0()) i"&ut
"c N #electio".4olum"s.4ou"t
-f "c RI 1 Te"
Ms%!o) PTe fu"ctio" sould 'e i" a si"%le colum".P
("d
("d -f
"r N #electio".Rows.4ou"t
-f "r R B Te"
Ms%!o) PTe colum" sould ave at least tree rows.P
("d
("d -f
' -"&ut te varia'le ) a"d its associated files
M3rom&t N PTe varia'le ) is i" colum"6P
MTitle N PRoot0i"der6 -"&ut )P
#et MRa"%e N >&&licatio".-"&ut!o)(M3rom&t, MTitle, Ty&e6NK)
MRa"%e.#elect
M0ormula N #electio".0ormula
MGalue N #electio".Galue
M0ormula#ave N #electio".0ormula
' Test te ) i"&ut
"c N #electio".4olum"s.4ou"t
-f "c RI 1 Te"
Ms%!o) PTe varia'le sould 'e i" a si"%le colum".P
("d
("d -f
-f "r RI #electio".Rows.4ou"t Te"
Ms%!o) PTe 0()) a"d ) colum"s must ave equal le"%ts.P
("d
("d -f
' 4ec1 for o"e root
' :ote6 a" odd "um'er of roots will also &ass tis test
00irst N 0Galue(1, 1)
0Last N 0Galue("r, 1)
-f 00irst * 0Last IN 0 Te"
Ms%!o) PTe array sould e"com&ass a si"%le root.P
("d
("d -f
' #et te resolutio"< 0Res must 'e &ositive
0Res N 0.00000000000002
' #u&&ress scree" u&dati"%
>&&licatio".#cree"5&dati"% N 0alse
' !isectio"
: N 0
=o
MRa"%e.#elect
M0irst N MGalue(1, 1)
MLast N MGalue("r, 1)
M:ew N (M0irst J MLast) C 2
MGalue(2, 1) N M:ew
#electio".Galue N MGalue

0Ra"%e.#elect
0Galue N #electio".Galue
00irst N 0Galue(1, 1)
0Last N 0Galue("r, 1)
0:ew N 0Galue(2, 1)

MRa"%e.#elect
-f 00irst * 0:ew N 0 Te" 8oTo a
-f 00irst * 0:ew I 0 Te"
0or i N 1 To "r
MGalue(i, 1) N M:ew J Q
(MLast + M:ew) * (i + 1) C ("r + 1)
:e)t i
Ratio N >'s((0Last + 0:ew) C (MLast + M:ew))
("d -f
-f 00irst * 0:ew R 0 Te"
0or i N 1 To "r
MGalue(i, 1) N M0irst J Q
(M:ew + M0irst) * (i + 1) C ("r + 1)
:e)t i
Ratio N >'s((0:ew + 00irst) C (M:ew + M0irst))
("d -f
: N : J 1
#electio".Galue N MGalue
Loo& 5"til >'s(0Last + 00irst) R 0Res 2r : N 100
' Restore data i"&ut area a"d dis&lay te fou"d root
a6
MRa"%e.#elect
#electio".0ormula N M0ormula#ave
0Ra"%e.#elect
#electio".0ormula N 00ormula#ave
-f Ratio I 1(J20 Te"
Ms%!o) P#i"%ularity at ) N P ? M:ew
(lse
Ms%!o) PRoot at ) N P ? M:ew
("d -f
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''***************************************''''''''''
''''''''''* *''''''''''
''''''''''* Mo%ie (emonstration Macros *''''''''''
''''''''''* *''''''''''
''''''''''***************************************''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' Te followi"% macros merely demo"strate ow to ma1e
' sim&le ()cel 'movies'. Teir use is illustrated i"
' sectio" 1.A of >(B.
'
''''''''''''''''''''''' Movie=emo 1 '''''''''''''''''''''''
'
' Tis demo"stratio" macro requires tat you e"ter te
' "um'er 0 i" cells >1 a"d !1, a"d te "um'er 10 i" >2 a"d
' !2. Te" i%li%t te area >16!2, a"d ma1e a corres&o"+
' di"% %ra&. 0ormat 'ot a)es to ave ma"ual scales from 0
' to 10. Ma1e sure tat te %ra& dis&lays !16!2 vs. >16>2
' as i"dividual &oi"ts ('mar1ers'). Te" call te macro,
' a"d e",oy te sow.
Su& Mo%ie(emo*()
Ra"%e(P>1P) N 0
Ra"%e(P>2P) N 0
0or i N 1 To 900
Ra"%e(P>1P) N 10 + 0.0H * >'s(i + 200)
Ra"%e(P>2P) N 10 * ()&(+0.001 * (i + B00) ; 2)
>&&licatio".#cree"5&dati"% N True
:e)t i
Ra"%e(P>1P) N 0
Ra"%e(P>2P) N 0
("d #u'
''''''''''''''''''''''' Movie=emo 2 '''''''''''''''''''''''
'
' Tis demo"stratio" macro requires tat you e"ter te "um+
' 'er 0 i" cells D1 a"d -1, a"d te "um'er 10 i" D2 a"d -2.
' Te" i%li%t te area D16-2, a"d ma1e a corres&o"di"%
' %ra&. 0ormat 'ot a)es to ave ma"ual scales from 0 to
' 10. Ma1e sure tat te %ra& dis&lays -16-2 vs. D16D2 as
' i"dividual &oi"ts ('mar1ers') co""ected 'y a li"e. Te"
' call te macro.
Su& Mo%ie(emo;()
Ra"%e(PD1P) N H6 Ra"%e(P-1P) N 1
Ra"%e(PD2P) N H6 Ra"%e(P-2P) N H
'>&&licatio".#cree"5&dati"% N True
0or i N 1 To 1000
Ra"%e(PD1P) N H + H * #i"(0.0A * i)
Ra"%e(P-1P) N H + H * 4os(0.0* * i)
>&&licatio".#cree"5&dati"% N True
:e)t i
Ra"%e(PD1P) N H6 Ra"%e(P-1P) N 1
Ra"%e(PD2P) N H6 Ra"%e(P-2P) N H
("d #u'
''''''''''''''''''''''' Movie=emo B '''''''''''''''''''''''
' Tis demo"stratio" macro requires tat you e"ter te
' "um'ers 0 trou% 10 i" cells >1H trou% >2H, a"d te
' "um'er H i" cells !1H6!2H. >%ai" use a %ra& wit ma"ual
' scales from 0 to 10, a"d dis&lay te data i" !1H6!2H vs.
' >1H6>2H as mar1ers &lus (smooted) co""ecti"% li"es.
Su& Mo%ie(emo+()
Ra"%e(P>1HP) N 06 Ra"%e(P!1HP) N H
Ra"%e(P>1AP) N 16 Ra"%e(P!1AP) N H
Ra"%e(P>1*P) N 26 Ra"%e(P!1*P) N H
Ra"%e(P>1KP) N B6 Ra"%e(P!1KP) N H
Ra"%e(P>1@P) N 96 Ra"%e(P!1@P) N H
Ra"%e(P>20P) N H6 Ra"%e(P!20P) N H
Ra"%e(P>21P) N A6 Ra"%e(P!21P) N H
Ra"%e(P>22P) N *6 Ra"%e(P!22P) N H
Ra"%e(P>2BP) N K6 Ra"%e(P!2BP) N H
Ra"%e(P>29P) N @6 Ra"%e(P!29P) N H
Ra"%e(P>2HP) N 106 Ra"%e(P!2HP) N H
>&&licatio".#cree"5&dati"% N True
0or i N 1 To 100
>&&licatio".#cree"5&dati"% N 0alse
Ra"%e(P!1HP) N H J 0.09 * i * #i"(0.01 * i)
Ra"%e(P!1AP) N H J 0.09 * i * #i"(0.01 * i + 100)
Ra"%e(P!1*P) N H J 0.09 * i * #i"(0.01 * i + 200)
Ra"%e(P!1KP) N H J 0.09 * i * #i"(0.01 * i + B00)
Ra"%e(P!1@P) N H J 0.09 * i * #i"(0.01 * i + 900)
Ra"%e(P!20P) N H J 0.09 * i * #i"(0.01 * i + H00)
Ra"%e(P!21P) N H J 0.09 * i * #i"(0.01 * i + A00)
Ra"%e(P!22P) N H J 0.09 * i * #i"(0.01 * i + *00)
Ra"%e(P!2BP) N H J 0.09 * i * #i"(0.01 * i + K00)
Ra"%e(P!29P) N H J 0.09 * i * #i"(0.01 * i + @00)
Ra"%e(P!2HP) N H J 0.09 * i * #i"(0.01 * i + 1000)
>&&licatio".#cree"5&dati"% N True
:e)t i
0or i N 101 To @00
>&&licatio".#cree"5&dati"% N 0alse
Ra"%e(P!1HP) N H J 9 * #i"(0.01 * i)
Ra"%e(P!1AP) N H J 9 * #i"(0.01 * i + 100)
Ra"%e(P!1*P) N H J 9 * #i"(0.01 * i + 200)
Ra"%e(P!1KP) N H J 9 * #i"(0.01 * i + B00)
Ra"%e(P!1@P) N H J 9 * #i"(0.01 * i + 900)
Ra"%e(P!20P) N H J 9 * #i"(0.01 * i + H00)
Ra"%e(P!21P) N H J 9 * #i"(0.01 * i + A00)
Ra"%e(P!22P) N H J 9 * #i"(0.01 * i + *00)
Ra"%e(P!2BP) N H J 9 * #i"(0.01 * i + K00)
Ra"%e(P!29P) N H J 9 * #i"(0.01 * i + @00)
Ra"%e(P!2HP) N H J 9 * #i"(0.01 * i + 1000)
>&&licatio".#cree"5&dati"% N True
:e)t i
0or i N @01 To 1000
>&&licatio".#cree"5&dati"% N 0alse
Ra"%e(P!1HP) N H J 0.09 * (1000 + i) * #i"(0.01 * i)
Ra"%e(P!1AP) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + 100)
Ra"%e(P!1*P) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + 200)
Ra"%e(P!1KP) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + B00)
Ra"%e(P!1@P) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + 900)
Ra"%e(P!20P) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + H00)
Ra"%e(P!21P) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + A00)
Ra"%e(P!22P) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + *00)
Ra"%e(P!2BP) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + K00)
Ra"%e(P!29P) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + @00)
Ra"%e(P!2HP) N Q
H J 0.09 * (1000 + i) * #i"(0.01 * i + 1000)
>&&licatio".#cree"5&dati"% N True
:e)t i
Ra"%e(P>1HP) N 06 Ra"%e(P!1HP) N H
Ra"%e(P>1AP) N 16 Ra"%e(P!1AP) N H
Ra"%e(P>1*P) N 26 Ra"%e(P!1*P) N H
Ra"%e(P>1KP) N B6 Ra"%e(P!1KP) N H
Ra"%e(P>1@P) N 96 Ra"%e(P!1@P) N H
Ra"%e(P>20P) N H6 Ra"%e(P!20P) N H
Ra"%e(P>21P) N A6 Ra"%e(P!21P) N H
Ra"%e(P>22P) N *6 Ra"%e(P!22P) N H
Ra"%e(P>2BP) N K6 Ra"%e(P!2BP) N H
Ra"%e(P>29P) N @6 Ra"%e(P!29P) N H
Ra"%e(P>2HP) N 106 Ra"%e(P!2HP) N H
("d #u'
''''''''''''''''''''''' Movie=emo 9 '''''''''''''''''''''''
'
' Tis demo"stratio" macro requires tat you e"ter te
' "um'ers 0, 0, H, H, H, H, 10 i" cells >2@6>BA, a"d te
' "um'er 0,1,*,H,H,H,H,0 i" cells !2@6!BA. >%ai" use a
' %ra& wit ma"ual scales from 0 to 10, a"d dis&lay te
' data as i"dividually disti"ct &oi"ts, eac of a differe"t
' ty&e a"dCor color. 0or e)am&le, &oi"t >B2,!B2 mi%t 'e a
' ollow 'lac1 circle of si7e 1K, &oi"t >BB,!BB a ollow
' red circle of si7e 19, &oi"t >B9,!B9 a ollow 'lac1 cir+
' cle of si7e @, a"d &oi"t >BH,!BH 'e a solid red circle of
' si7e A. >lso ma1e te oter data mar1ers disti"ct.
Su& Mo%ie(emo<()
Ra"%e(P>1P) N 06 Ra"%e(P!1P) N 0
Ra"%e(P>2P) N 06 Ra"%e(P!2P) N 1
Ra"%e(P>BP) N H6 Ra"%e(P!BP) N @
Ra"%e(P>9P) N H6 Ra"%e(P!9P) N H
Ra"%e(P>HP) N H6 Ra"%e(P!HP) N H
Ra"%e(P>AP) N H6 Ra"%e(P!AP) N H
Ra"%e(P>*P) N H6 Ra"%e(P!*P) N H
Ra"%e(P>KP) N 106 Ra"%e(P!KP) N 0
>&&licatio".#cree"5&dati"% N True
>&&licatio".Golatile True
0or i N 1 To 1000
>&&licatio".#cree"5&dati"% N 0alse
Ra"%e(P>1P) N H + H * #i"(0.01 * (i + H00))
Ra"%e(P!1P) N H + H * #i"(0.01 * (i + H00))
Ra"%e(P>2P) N Ra"%e(P>2P) J 0.01
Ra"%e(P!2P) N H + 9 * 4os(0.0B * i)
Ra"%e(P>BP) N H J 9 * #i"(0.2 * i)
Ra"%e(P!BP) N H + 9 * 4os(0.2 * i)
-f 4='l(i) C 1A0 + 4-"t(i C 1A0) N 0 Te"
Ra"%e(P>9P) N H J (H * R"d() + 2.H)
Ra"%e(P!9P) N H J (H * R"d() + 2.H)
("d -f
-f 4='l(i) C 1*0 + 4-"t(i C 1*0) N 0 Te"
Ra"%e(P>HP) N Ra"%e(P>9P)
Ra"%e(P!HP) N Ra"%e(P!9P)
("d -f
-f 4='l(i) C 1K0 + 4-"t(i C 1K0) N 0 Te"
Ra"%e(P>AP) N Ra"%e(P>9P)
Ra"%e(P!AP) N Ra"%e(P!9P)
("d -f
-f 4='l(i) C 1@0 + 4-"t(i C 1@0) N 0 Te"
Ra"%e(P>*P) N Ra"%e(P>9P)
Ra"%e(P!*P) N Ra"%e(P!9P)
("d -f
-f 4='l(i) C 10 + 4-"t(i C 10) N 0 Te"
Ra"%e(P>KP) N H J H * #i"(0.01 * (i + H00))
("d -f
Ra"%e(P!KP) N Ra"%e(P!KP) J 0.01
>&&licatio".#cree"5&dati"% N True
:e)t i
Ra"%e(P>1P) N 06 Ra"%e(P!1P) N 0
Ra"%e(P>2P) N 06 Ra"%e(P!2P) N 1
Ra"%e(P>BP) N H6 Ra"%e(P!BP) N @
Ra"%e(P>9P) N H6 Ra"%e(P!9P) N H
Ra"%e(P>HP) N H6 Ra"%e(P!HP) N H
Ra"%e(P>AP) N H6 Ra"%e(P!AP) N H
Ra"%e(P>*P) N H6 Ra"%e(P!*P) N H
Ra"%e(P>KP) N 106 Ra"%e(P!KP) N 0
("d #u'
''''''''''''''''''''''' Movie=emoH '''''''''''''''''''''''
'
' Tis demo"stratio" macro requires tat you e"ter te
' "um'ers 9, 9, 9, 9, A, A, A, a"d A i" cells D1H6D22,
' a"d te "um'er H i" cells -1H6-22. >%ai" use a %ra&
' wit ma"ual scales from 0 to 10, a"d dis&lay te &oi"ts
' D1H, -1H, a"d D1@6-1@ as small solid circles, &refera'ly
' of differe"t color, a"d te oters as lar%er, ollow
' (co"ce"tric) ri"%s arou"d tem.
Su& Mo%ie(emo=()
Ra"%e(PD1HP) N 96 Ra"%e(P-1HP) N H
Ra"%e(PD1AP) N 96 Ra"%e(P-1AP) N H
Ra"%e(PD1*P) N 96 Ra"%e(P-1*P) N H
Ra"%e(PD1KP) N 96 Ra"%e(P-1KP) N H
Ra"%e(PD1@P) N A6 Ra"%e(P-1@P) N H
Ra"%e(PD20P) N A6 Ra"%e(P-20P) N H
Ra"%e(PD21P) N A6 Ra"%e(P-21P) N H
Ra"%e(PD22P) N A6 Ra"%e(P-22P) N H
0or i N 1 To 2H2
Ra"%e(PD1HP) N 9 J 0.2 * #i"(0.1 * i)
Ra"%e(PD1AP) N 9 J 0.B * #i"(0.1 * i)
Ra"%e(PD1*P) N 9 J 0.9 * #i"(0.1 * i)
Ra"%e(PD1KP) N 9 J 0.H * #i"(0.1 * i)
Ra"%e(PD1@P) N A + 0.2 * #i"(0.1 * i)
Ra"%e(PD20P) N A + 0.B * #i"(0.1 * i)
Ra"%e(PD21P) N A + 0.9 * #i"(0.1 * i)
Ra"%e(PD22P) N A + 0.H * #i"(0.1 * i)
>&&licatio".#cree"5&dati"% N True
:e)t i
0or i N 2HB To H02
Ra"%e(PD1HP) N Q
H J 4os(0.02H * i) * (+1 J 0.2 * #i"(0.1 * i))
Ra"%e(P-1HP) N Q
H J #i"(0.02H * i) * (+1 J 0.2 * #i"(0.1 * i))
Ra"%e(PD1AP) N Q
H J 4os(0.02H * i) * (+1 J 0.B * #i"(0.1 * i))
Ra"%e(P-1AP) N Q
H J #i"(0.02H * i) * (+1 J 0.B * #i"(0.1 * i))
Ra"%e(PD1*P) N Q
H J 4os(0.02H * i) * (+1 J 0.9 * #i"(0.1 * i))
Ra"%e(P-1*P) N Q
H J #i"(0.02H * i) * (+1 J 0.9 * #i"(0.1 * i))
Ra"%e(PD1KP) N Q
H J 4os(0.02H * i) * (+1 J 0.H * #i"(0.1 * i))
Ra"%e(P-1KP) N Q
H J #i"(0.02H * i) * (+1 J 0.H * #i"(0.1 * i))
Ra"%e(PD1@P) N Q
H J 4os(0.02H * i) * (1 + 0.2 * #i"(0.1 * i))
Ra"%e(P-1@P) N Q
H J #i"(0.02H * i) * (1 + 0.2 * #i"(0.1 * i))
Ra"%e(PD20P) N Q
H J 4os(0.02H * i) * (1 + 0.B * #i"(0.1 * i))
Ra"%e(P-20P) N Q
H J #i"(0.02H * i) * (1 + 0.B * #i"(0.1 * i))
Ra"%e(PD21P) N Q
H J 4os(0.02H * i) * (1 + 0.9 * #i"(0.1 * i))
Ra"%e(P-21P) N Q
H J #i"(0.02H * i) * (1 + 0.9 * #i"(0.1 * i))
Ra"%e(PD22P) N Q
H J 4os(0.02H * i) * (1 + 0.H * #i"(0.1 * i))
Ra"%e(P-22P) N Q
H J #i"(0.02H * i) * (1 + 0.H * #i"(0.1 * i))
>&&licatio".#cree"5&dati"% N True
:e)t i
0or i N H0B To AB0
Ra"%e(PD1HP) N 9 J 0.2 * #i"(0.1 * i)
Ra"%e(PD1AP) N 9 J 0.B * #i"(0.1 * i)
Ra"%e(PD1*P) N 9 J 0.9 * #i"(0.1 * i)
Ra"%e(PD1KP) N 9 J 0.H * #i"(0.1 * i)
Ra"%e(PD1@P) N A + 0.2 * #i"(0.1 * i)
Ra"%e(PD20P) N A + 0.B * #i"(0.1 * i)
Ra"%e(PD21P) N A + 0.9 * #i"(0.1 * i)
Ra"%e(PD22P) N A + 0.H * #i"(0.1 * i)
>&&licatio".#cree"5&dati"% N True
:e)t i
Ra"%e(PD1HP) N 96 Ra"%e(P-1HP) N H
Ra"%e(PD1AP) N 96 Ra"%e(P-1AP) N H
Ra"%e(PD1*P) N 96 Ra"%e(P-1*P) N H
Ra"%e(PD1KP) N 96 Ra"%e(P-1KP) N H
Ra"%e(PD1@P) N A6 Ra"%e(P-1@P) N H
Ra"%e(PD20P) N A6 Ra"%e(P-20P) N H
Ra"%e(PD21P) N A6 Ra"%e(P-21P) N H
Ra"%e(PD22P) N A6 Ra"%e(P-22P) N H
>&&licatio".#cree"5&dati"% N True
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''*************************************'''''''''''
'''''''''''* *'''''''''''
'''''''''''* Insert MacroBundle Tool&ar *'''''''''''
'''''''''''* *'''''''''''
'''''''''''*************************************'''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' 35R32#(6
' Tis su'routi"e &laces a" e)tra tool'ar i" te ()cel
' s&readseet i" order to facilitate access to te custom
' macros of tis Macro!u"dle. Te M!Tool'ar sows seve"
' cate%ories, ma"y wit su'cate%ories, a"d &rovides access
' to all macros of te Macro!u"dle. To remove tis tool'ar,
' select RemoveM!Tool'ar i" te last cate%ory, Miscella"y.
' Eou ca" of course modify tis tool'ar i" order to delete
' macros you do "ot "eed a"dCor add your ow" custom macros.
' >ll macros, weter listed i" tis tool'ar or "ot, ca"
' always 'e called wit Tools I Macro I Macros or >lta0K.
' #5!R25T-:(#6
' >ll custom macros of te curre"t Macro!u"dle
' ca" 'e called wit tis tool'ar.
' L-M-T>T-2:#6
' Tis su'routi"e wor1s i" ()cel @* trou% ()cel 200B< it
' will "ot wor1 i" ()cel @H or i" earlier versio"s, wic
' a"dled tool'ars differe"tly. -t will wor1 wit ()cel
' 200*, 'ut tere must 'e &laced i" its =evelo&er ri''o".
' -f tat ri''o" does "ot already e)ist, create it as
' follows. (iter clic1 o" te 2ffice !utto" i" te to&
' left+a"d cor"er of te ()cel 200* s&readseet, select
' ()cel 2&tio"s, a"d &lace a tic1mar1 wit #ow =evelo&er
' ta', or sim&ly &ress >lt followed 'y te letters fid.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Su& InsertMBTool&ar()
=im T!ar >s 4omma"d!ar
=im !utto"1 >s 4omma"d!ar!utto"
=im !utto"2 >s 4omma"d!ar3o&u&
=im !utto"21 >s 4omma"d!ar3o&u&
=im !utto"210 >s 4omma"d!ar!utto"
=im !utto"211 >s 4omma"d!ar!utto"
=im !utto"22 >s 4omma"d!ar3o&u&
=im !utto"221 >s 4omma"d!ar!utto"
=im !utto"222 >s 4omma"d!ar!utto"
=im !utto"2B >s 4omma"d!ar3o&u&
=im !utto"2B0 >s 4omma"d!ar!utto"
=im !utto"2B1 >s 4omma"d!ar!utto"
=im !utto"29 >s 4omma"d!ar!utto"
=im !utto"2H >s 4omma"d!ar3o&u&
=im !utto"2H0 >s 4omma"d!ar!utto"
=im !utto"2H1 >s 4omma"d!ar!utto"
=im !utto"2A >s 4omma"d!ar3o&u&
=im !utto"2A0 >s 4omma"d!ar!utto"
=im !utto"2A1 >s 4omma"d!ar!utto"
=im !utto"2* >s 4omma"d!ar!utto"
=im !utto"B >s 4omma"d!ar3o&u&
=im !utto"B1 >s 4omma"d!ar!utto"
=im !utto"B2 >s 4omma"d!ar3o&u&
=im !utto"B21 >s 4omma"d!ar!utto"
=im !utto"B22 >s 4omma"d!ar!utto"
=im !utto"B2B >s 4omma"d!ar!utto"
=im !utto"BB >s 4omma"d!ar!utto"
=im !utto"9 >s 4omma"d!ar3o&u&
=im !utto"91 >s 4omma"d!ar3o&u&
=im !utto"911 >s 4omma"d!ar!utto"
=im !utto"912 >s 4omma"d!ar!utto"
=im !utto"92 >s 4omma"d!ar!utto"
=im !utto"9B >s 4omma"d!ar3o&u&
=im !utto"9B0 >s 4omma"d!ar!utto"
=im !utto"9B1 >s 4omma"d!ar!utto"
=im !utto"H >s 4omma"d!ar3o&u&
=im !utto"H1 >s 4omma"d!ar3o&u&
=im !utto"H11 >s 4omma"d!ar!utto"
=im !utto"H12 >s 4omma"d!ar!utto"
=im !utto"H2 >s 4omma"d!ar3o&u&
=im !utto"H21 >s 4omma"d!ar!utto"
=im !utto"H22 >s 4omma"d!ar!utto"
=im !utto"H2B >s 4omma"d!ar!utto"
=im !utto"H29 >s 4omma"d!ar!utto"
=im !utto"A >s 4omma"d!ar3o&u&
=im !utto"A1 >s 4omma"d!ar3o&u&
=im !utto"A11 >s 4omma"d!ar!utto"
=im !utto"A12 >s 4omma"d!ar!utto"
=im !utto"A2 >s 4omma"d!ar3o&u&
=im !utto"A21 >s 4omma"d!ar!utto"
=im !utto"A22 >s 4omma"d!ar!utto"
=im !utto"AB >s 4omma"d!ar!utto"
=im !utto"AB01 >s 4omma"d!ar!utto"
=im !utto"A9 >s 4omma"d!ar!utto"
=im !utto"AH >s 4omma"d!ar3o&u&
=im !utto"AH1 >s 4omma"d!ar!utto"
=im !utto"AH2 >s 4omma"d!ar!utto"
=im !utto"* >s 4omma"d!ar3o&u&
=im !utto"*1 >s 4omma"d!ar3o&u&
=im !utto"*10 >s 4omma"d!ar!utto"
=im !utto"*11 >s 4omma"d!ar!utto"
=im !utto"*12 >s 4omma"d!ar!utto"
=im !utto"*1B >s 4omma"d!ar!utto"
=im !utto"*19 >s 4omma"d!ar!utto"
=im !utto"*2 >s 4omma"d!ar3o&u&
=im !utto"*20 >s 4omma"d!ar!utto"
=im !utto"*21 >s 4omma"d!ar!utto"
=im !utto"*22 >s 4omma"d!ar!utto"
=im !utto"*2B >s 4omma"d!ar!utto"
=im !utto"*B >s 4omma"d!ar3o&u&
=im !utto"*B0 >s 4omma"d!ar!utto"
=im !utto"*B1 >s 4omma"d!ar!utto"
=im !utto"*B2 >s 4omma"d!ar!utto"
=im !utto"*BB >s 4omma"d!ar!utto"
=im !utto"K >s 4omma"d!ar3o&u&
=im !utto"K1 >s 4omma"d!ar3o&u&
=im !utto"K10 >s 4omma"d!ar!utto"
=im !utto"K11 >s 4omma"d!ar!utto"
=im !utto"K2 >s 4omma"d!ar!utto"
=im !utto"KB >s 4omma"d!ar3o&u&
=im !utto"KB0 >s 4omma"d!ar!utto"
=im !utto"KB1 >s 4omma"d!ar!utto"
=im !utto"KB2 >s 4omma"d!ar!utto"
=im !utto"KBB >s 4omma"d!ar!utto"
=im !utto"KB9 >s 4omma"d!ar!utto"
=im !utto"K9 >s 4omma"d!ar3o&u&
=im !utto"K91 >s 4omma"d!ar!utto"
=im !utto"K92 >s 4omma"d!ar!utto"
' -" order to &reve"t co"flicts, delete a"y earlier
' of te Macro!u"dle tool'ar, if &rese"t
2" (rror Resume :e)t
4omma"d!ars(PMacro!u"dleP).=elete
' 4reate a comma"d'ar
#et T!ar N 4omma"d!ars.>dd
$it T!ar
.:ame N PMacro!u"dleP
.3ositio" N mso!arTo&
.Gisi'le N True
("d $it
#et !utto"1 N 4omma"d!ars(PMacro!u"dleP) Q
.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"1
.4a&tio" N P3ro&a%atio"P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P3ro&a%atio"P
("d $it
' 4reate me"u for Li"ear L#
#et !utto"2 N 4omma"d!ars(PMacro!u"dleP) Q
.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"2.4a&tio" N Pli"ear L#P
!utto"2.!e%i"8rou& N True
' 4reate su'me"u for L#
#et !utto"21 N !utto"2.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"21.4a&tio" N P L#P
!utto"21.Toolti&Te)t N PDi%li%t arrayP ? 4r(1B) ? Q
P'efore &ressi"%P ? 4r(1B) ? PL#2 or L#-P
' 4reate 'utto"s for L#2 a"d L#-
#et !utto"210 N !utto"21.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"210
.4a&tio" N PL#2P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PL#2P
("d $it
#et !utto"211 N !utto"21.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"211
.4a&tio" N PL#-P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PL#-P
("d $it
' 4reate a su'me"u for (L#
#et !utto"22 N !utto"2.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"22.4a&tio" N P(L#P
!utto"22.Toolti&Te)t N PDi%li%t arrayP ? 4r(1B) ? Q
P'efore &ressi"%P ? 4r(1B) ? P(L#auto or (L#fi)edP
' 4reate 'utto"s for (L#auto a"d (L#fi)ed
#et !utto"221 N !utto"22.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
!utto"221.4a&tio" N P(L#autoP
!utto"221.2">ctio" N P(L#autoP
#et !utto"222 N !utto"22.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
!utto"222.4a&tio" N P(L#fi)edP
!utto"222.2">ctio" N P(L#fi)edP
' 4reate a su'me"u for $L#
#et !utto"2B N !utto"2.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"2B.4a&tio" N P$L#P
!utto"2B.Toolti&Te)t N PDi%li%t arrayP ? 4r(1B) ? Q
P'efore &ressi"%P ? 4r(1B) ? P$L#2 or $L#-P
' 4reate 'utto"s for $L#2 a"d $L#-
#et !utto"2B0 N !utto"2B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
!utto"2B0.4a&tio" N P$L#2P
!utto"2B0.2">ctio" N P$L#2P
#et !utto"2B1 N !utto"2B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
!utto"2B1.4a&tio" N P$L#-P
!utto"2B1.2">ctio" N P$L#-P
' 4reate a 'utto" for #cale!y#f
#et !utto"29 N !utto"2.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"29
.4a&tio" N P8rade!y#fP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P8rade!y#f P
("d $it
' 4reate a su'me"u for L#3oly
#et !utto"2H N !utto"2.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"2H.4a&tio" N PL#3olyP
!utto"2H.Toolti&Te)t N PDi%li%t arrayP ? 4r(1B) ? Q
P'efore &ressi"%P ? 4r(1B) ? PL#3oly0 or L#3oly1P
' 4reate 'utto"s for L#3oly2 a"d L#3oly-
#et !utto"2H0 N !utto"2H.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"2H0
.4a&tio" N PL#3oly2P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PL#3oly2P
("d $it
#et !utto"2H1 N !utto"2H.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"2H1
.4a&tio" N PL#3oly-P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PL#3oly-P
("d $it
' 4reate a su'me"u for L#Multi
#et !utto"2A N !utto"2.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"2A.4a&tio" N PL#MultiP
!utto"2A.Toolti&Te)t N PDi%li%t arrayP ? 4r(1B) ? Q
P'efore &ressi"%P ? 4r(1B) ? PL#Multi0 or L#Multi1P
' 4reate 'utto"s for L#Multi2 a"d L#Multi-
#et !utto"2A0 N !utto"2A.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"2A0
.4a&tio" N PL#Multi2P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PL#Multi2P
("d $it
#et !utto"2A1 N !utto"2A.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"2A1
.4a&tio" N PL#Multi-P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PL#Multi-P
("d $it
' 4reate a 'utto" for 3ermute
#et !utto"2* N !utto"2.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"2*
.4a&tio" N PL#3ermuteP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PL#3ermuteP
("d $it
' 4reate a me"u for :o"li"ear L#
#et !utto"B N 4omma"d!ars(PMacro!u"dleP) Q
.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"B.4a&tio" N P"o"li"ear L#P
!utto"B.!e%i"8rou& N True
' 4reate a 'utto" for #olver>id
#et !utto"B1 N !utto"B.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"B1
.4a&tio" N P#olver>idP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P#olver>idP
("d $it
' 4reate a 'utto" for 4olum"#olver
#et !utto"B2 N !utto"B.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"B2.4a&tio" N P4olum"#olverP
' 4reate su'me"us for 4ol#olverMa), 4ol#olverMi",
' a"d 4ol#olverGalue res&ectively
#et !utto"B21 N !utto"B2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
!utto"B21.4a&tio" N P4olum"#olverMa)P
!utto"B21.2">ctio" N P4olum"#olverMa)P
#et !utto"B22 N !utto"B2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
!utto"B22.4a&tio" N P4olum"#olverMi"P
!utto"B22.2">ctio" N P4olum"#olverMi"P
#et !utto"B2B N !utto"B2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
!utto"B2B.4a&tio" N P4olum"#olverGalueP
!utto"B2B.2">ctio" N P4olum"#olverGalueP
' 4reate a 'utto" for #olver#ca"
#et !utto"BB N !utto"B.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"BB
.4a&tio" N P#olver#ca"P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P#olver#ca"P
("d $it
' 4reate a 'utto" for Tra"sforms
#et !utto"9 N 4omma"d!ars(PMacro!u"dleP).4o"trols Q
.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"9.4a&tio" N Ptra"sformsP
!utto"9.!e%i"8rou& N True
' 4reate a 'utto" for 0ourier
#et !utto"91 N !utto"9.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"91.4a&tio" N P0ourierP
!utto"91.Toolti&Te)t N PDi%li%t arrayP ? 4r(1B) ? Q
P'efore &ressi"%P ? 4r(1B) ? P0orward0T orP ? Q
4r(1B) ? P-"verse0TP
' 4reate su'me"us for 0orward0T a"d -"verse0T
#et !utto"911 N !utto"91.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"911
.4a&tio" N P0orward0TP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P0orward0TP
("d $it
#et !utto"912 N !utto"91.4o"trols. Q
>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"912
.4a&tio" N P-"verse0TP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P-"verse0TP
("d $it
' 4reate a 'utto" for 8a'or
#et !utto"92 N !utto"9.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"92
.4a&tio" N P8a'orP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P8a'orP
("d $it
' 4reate a 'utto" for 2rto
#et !utto"9B N !utto"9.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"9B.4a&tio" N P2rtoP
' 4reate su'me"us for 2rto2 a"d 2rto-
#et !utto"9B0 N !utto"9B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"9B0
.4a&tio" N P2rto2P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P2rto2P
("d $it
#et !utto"9B1 N !utto"9B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"9B1
.4a&tio" N P2rto-P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P2rto-P
("d $it
' 4reate a 'utto" for (de)co"volutio"
#et !utto"H N 4omma"d!ars(PMacro!u"dleP) Q
.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"H.4a&tio" N P(de)co"volutio"P
!utto"H.!e%i"8rou& N True
' 4reate a 'utto" for co"volutio"
#et !utto"H1 N !utto"H.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"H1.4a&tio" N Pco"volutio"P
' 4reate su'me"us for 4o"volve a"d 4o"volve0T
#et !utto"H11 N !utto"H1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"H11
.4a&tio" N P4o"volveP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P4o"volveP
("d $it
#et !utto"H12 N !utto"H1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"H12
.4a&tio" N P4o"volve0TP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P4o"volve0TP
("d $it
' 4reate a 'utto" for =eco"volutio"
#et !utto"H2 N !utto"H.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"H2.4a&tio" N Pdeco"volutio"P
' 4reate su'me"us for =eco"volve, =eco"volve0T,
' =eco"volve-t0, a"d =eco"volve-t1
#et !utto"H21 N !utto"H2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"H21
.4a&tio" N P=eco"volveP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P=eco"volveP
("d $it
#et !utto"H22 N !utto"H2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"H22
.4a&tio" N P=eco"volve0TP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P=eco"volve0TP
("d $it
#et !utto"H2B N !utto"H2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"H2B
.4a&tio" N P=eco"volve-t0P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P=eco"volve-t0P
("d $it
#et !utto"H29 N !utto"H2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"H29
.4a&tio" N P=eco"volve-t1P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P=eco"volve-t1P
("d $it
' 4reate a 'utto" for calculus
#et !utto"A N 4omma"d!ars(PMacro!u"dleP) Q
.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"A.4a&tio" N PcalculusP
!utto"A.!e%i"8rou& N True
' 4reate a 'utto" for Rom'er%
#et !utto"A1 N !utto"A.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"A1.4a&tio" N PRom'er%P
' 4reate su'me"us for Rom'er%>uto a"d Rom'er%#&ecify
#et !utto"A11 N !utto"A1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"A11
.4a&tio" N PRom'er%>utoP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PRom'er%>utoP
("d $it
#et !utto"A12 N !utto"A1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"A12
.4a&tio" N PRom'er%#&ecifyP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PRom'er%#&ecifyP
("d $it
' 4reate a 'utto" for Tra&e7
#et !utto"A2 N !utto"A.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"A2.4a&tio" N PTra&e7P
' 4reate su'me"us for Tra&e7>uto a"d Tra&e7#&ecify
#et !utto"A21 N !utto"A2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"A21
.4a&tio" N PTra&e7>utoP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PTra&e7>utoP
("d $it
#et !utto"A22 N !utto"A2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"A22
.4a&tio" N PTra&e7#&ecifyP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PTra&e7#&ecifyP
("d $it
' 4reate a 'utto" for =eriv
#et !utto"AB N !utto"A.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"AB
.4a&tio" N P=erivP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P=erivP
("d $it
' 4reate a 'utto" for =eriv1
#et !utto"AB01 N !utto"A.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"AB01
.4a&tio" N P=eriv1P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P=eriv1P
("d $it
' 4reate a 'utto" for =eriv#ca"
#et !utto"A9 N !utto"A.4o"trols.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"A9
.4a&tio" N P=eriv#ca"P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P=eriv#ca"P
("d $it
' 4reate a 'utto" for #emi-"te%ratio"
' a"d #emi=iffere"tiatio"
#et !utto"AH N !utto"A.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"AH.4a&tio" N P#emi=iffC-"tP
' 4reate 'utto"s for #emi=iffere"tiate a"d #emi-"te%rate
#et !utto"AH1 N !utto"AH.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"AH1
.4a&tio" N P#emi-"te%rateP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P#emi-"te%rateP
("d $it
#et !utto"AH2 N !utto"AH.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"AH2
.4a&tio" N P#emi=iffere"tiateP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P#emi=iffere"tiateP
("d $it
' 4reate a 'utto" for ma&&er
#et !utto"* N 4omma"d!ars(PMacro!u"dleP).4o"trols Q
.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"*.4a&tio" N Pma&&erP
!utto"*.!e%i"8rou& N True
' 4reate a 'utto" for 8radual Ma&&er
#et !utto"*1 N !utto"*.4o"trols Q
.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"*1.Toolti&Te)t N P%radual scaleP
!utto"*1.4a&tio" N P8radual Ma&&erP
' 4reate su'me"us for Ma&&er 0 trou% B
#et !utto"*10 N !utto"*1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*10
.4a&tio" N P%ray scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er0P
("d $it
#et !utto"*11 N !utto"*1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*11
.4a&tio" N Ps&ectrumP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er1P
("d $it
#et !utto"*12 N !utto"*1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*12
.4a&tio" N Pred scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er2P
("d $it
#et !utto"*1B N !utto"*1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*1B
.4a&tio" N P'lue scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&erBP
("d $it
' 4reate a 'utto" for @+'a"d ma&&er
#et !utto"*2 N !utto"*.4o"trols Q
.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"*2.Toolti&Te)t N P@+'a"d scaleP
!utto"*2.4a&tio" N P@+!a"d Ma&&erP
' 4reate su'me"us for Ma&&er00 trou% Ma&&erBB
#et !utto"*20 N !utto"*2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*20
.4a&tio" N P%ray scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er00P
("d $it
#et !utto"*21 N !utto"*2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*21
.4a&tio" N Ps&ectrumP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er11P
("d $it
#et !utto"*22 N !utto"*2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*22
.4a&tio" N Pred scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er22P
("d $it
#et !utto"*2B N !utto"*2.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*2B
.4a&tio" N P'lue scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&erBBP
("d $it
' 4reate a 'utto" for 1*+'a"d ma&&er
#et !utto"*B N !utto"*.4o"trols Q
.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"*B.Toolti&Te)t N P1*+'a"d scaleP
!utto"*B.4a&tio" N P1*+!a"d Ma&&erP
' 4reate su'me"us for Ma&&er000 trou% Ma&&erBBB
#et !utto"*B0 N !utto"*B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*B0
.4a&tio" N P%ray scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er000P
("d $it
#et !utto"*B1 N !utto"*B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*B1
.4a&tio" N Ps&ectrumP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er111P
("d $it
#et !utto"*B2 N !utto"*B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*B2
.4a&tio" N Pred scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&er222P
("d $it
#et !utto"*BB N !utto"*B.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"*BB
.4a&tio" N P'lue scaleP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMa&&erBBBP
("d $it
' 4reate a 'utto" for miscella"y
#et !utto"K N 4omma"d!ars(PMacro!u"dleP).4o"trols Q
.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"K.4a&tio" N Pmiscella"yP
!utto"K.!e%i"8rou& N True
' 4reate a 'utto" for #ca"0
#et !utto"K1 N !utto"K.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"K1.Toolti&Te)t N P#elect #ca"00 for 0(),y) orP Q
? 4r(1B) ? P#ca"01 for added -soList P
!utto"K1.4a&tio" N P#ca"0P
' 4reate su'me"us for #ca"00 a"d #ca"01
#et !utto"K10 N !utto"K1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"K10
.4a&tio" N P#ca"00P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P#ca"00P
("d $it
#et !utto"K11 N !utto"K1.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"K11
.4a&tio" N P#ca"01P
.#tyle N mso!utto"4a&tio"
.2">ctio" N P#ca"01P
("d $it
' 4reate a 'utto" for Root0i"der
#et !utto"K2 N !utto"K.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"K2
.4a&tio" N PRoot0i"derP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PRoot0i"derP
("d $it
' 4reate a 'utto" for Movie=emos
#et !utto"KB N !utto"K.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"KB.4a&tio" N PMovie=emosP
' 4reate su'me"us for Movie=emo1 trou% Movie=emoH
#et !utto"KB0 N !utto"KB.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"KB0
.4a&tio" N PMovie=emo1P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMovie=emo1P
("d $it
#et !utto"KB1 N !utto"KB.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"KB1
.4a&tio" N PMovie=emo2P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMovie=emo2P
("d $it
#et !utto"KB2 N !utto"KB.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"KB2
.4a&tio" N PMovie=emoBP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMovie=emoBP
("d $it
#et !utto"KBB N !utto"KB.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"KBB
.4a&tio" N PMovie=emo9P
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMovie=emo9P
("d $it
#et !utto"KB9 N !utto"KB.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"KB9
.4a&tio" N PMovie=emoHP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PMovie=emoHP
("d $it
' 4reate a 'utto" for M!Tool'ar
#et !utto"K9 N !utto"K.4o"trols.>dd(Ty&e6Nmso4o"trol3o&u&)
!utto"K9.4a&tio" N PM!Tool'arP
' 4reate su'me"us for -"sertM!Tool'ar a"d RemoveM!Tool'ar
#et !utto"K91 N !utto"K9.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"K91
.4a&tio" N P-"sertM!Tool'arP
.#tyle N mso!utto"4a&tio"
.2">ctio" N P-"sertM!Tool'arP
("d $it
#et !utto"K92 N !utto"K9.4o"trols Q
.>dd(Ty&e6Nmso4o"trol!utto")
$it !utto"K92
.4a&tio" N PRemoveM!Tool'arP
.#tyle N mso!utto"4a&tio"
.2">ctio" N PRemoveM!Tool'arP
("d $it

("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''*************************************'''''''''''
'''''''''''* *'''''''''''
'''''''''''* Remo%e MacroBundle Tool&ar *'''''''''''
'''''''''''* *'''''''''''
'''''''''''*************************************'''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
Su& Remo%eMBTool&ar()
2" (rror Resume :e)t
4omma"d!ars(PMacro!u"dleP).=elete
("d #u'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''*************************************'''''''''''
'''''''''''* *'''''''''''
'''''''''''* Lagrange Interpolation *'''''''''''
'''''''''''* *'''''''''''
'''''''''''*************************************'''''''''''
''''''''''''''''''''''''''''''''''''''''''' (c) R. de Levie
''''''''''''''''''''''''''''''''''''''''''' v 12, May 2012
' (M>M3L(6
'
' 5se of tis sta"d+alo"e fu"ctio" is illustrated i" >(B
' sectio" 1.10.
Function Lagrange(M>rray, E>rray, M, m)
' m de"otes te order of te &oly"omial used,
' a"d must 'e a" i"te%er 'etwee" 1 a"d 19
=im Row >s -"te%er, i >s -"te%er, , >s -"te%er
=im Term >s =ou'le, E >s =ou'le
Row N >&&licatio".Matc(M, M>rray, 1)
-f Row R (m J 1) C 2 Te" Row N (m J 1) C 2
-f Row I M>rray.4ou"t + (m J 1) C 2 Te" Q
Row N M>rray.4ou"t + (m J 1) C 2
0or i N Row + (m + 1) C 2 To Row J (m J 1) C 2
Term N 1
0or , N Row + (m + 1) C 2 To Row J (m J 1) C 2
-f i RI , Te" Term N Term * (M + M>rray(,)) C Q
(M>rray(i) + M>rray(,))
:e)t ,
E N E J Term * E>rray(i)
:e)t i
La%ra"%e N E
("d 0u"ctio"

You might also like