{VERSION 6 0 "IBM INTEL LINUX" "6.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {EXCHG {PARA 0 "" 0 "" {TEXT -1 49 "LeastSquares915.mws\nThu S ep 15 08:34:32 MDT 2005\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 94 "These \"with\" commands make items available from the Map le packages \"plots\" and \"CurveFitting\":" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "with(plots, displ ay); " }{TEXT -1 46 "To make \"display\" available to this worksheet. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "with(CurveFitting, Leas tSquares); " }{TEXT -1 24 "Ditto for \"LeastSquares\"" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 223 "Maple ha s recently overhauled/redesigned their Least-Squares. The \"with(stat s)\" environment described in chapter 3 is still available. Here we l ook at the new ways Maple has come up with to do least-squares curve f itting." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 76 "We begin with a couple of famous list-processing functions, \"map \" and \"zip\":" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 136 "Here are data cribbed from page 42 of our text. Th e square brackets delimit Maple lists (as oppsed to Maple sets, delimi ted by \{ and \}:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 28 "Ex2_xRow := [1,2,3,4,5,6,7];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "Ex2_yRow := [2.2, 3.7, 5.5, 5.9, 5. 6, 4.2, 3.1];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 120 "To make a scatter plot of these data, we need to matc h them up in points. The Maple command \"zip\" does this as follows. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 217 "Firs t we set up the function \"makepoint\" which takes an ordered pair of \+ values and resturns a Maple list of two items. Such a list is how Map le expresses points in the two-dimensional Cartesian plane. We follo w the" }}{PARA 0 "" 0 "" {TEXT -1 113 "\"makepoint\" definition with a test invocation just to make sure \"makepoint\" is \"there\" and doin g what we expect. " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "makepoint := (x,y) -> [x,y]; " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "makepoint(3,Pi);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 97 "Nopw we \"zip\" our \"makepoint\" function through the pair of lists. The Maple \"zi p\" command feeds" }}{PARA 0 "" 0 "" {TEXT -1 220 "\"makepoint\" its \+ x-value from the first list, and the y-value from the second list. In this case, \"zip\" makes us a list of Maple points. You might want to check what happens if we change \"makepoint\" to add x and y...." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "PTS := zip( makepoint, Ex2_xRow, Ex2_yRow);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 48 "Next we go for \+ a scatterplot of our data points:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "plot(PTS);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 91 "We'd rather a p lot of the discrete points, so we add on plot option \"style=POINT\", \+ and then" }}{PARA 0 "" 0 "" {TEXT -1 60 "plot option \"symbolsize=20\" to make the data points bigger." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "plot(PTS, style=POINT);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "plot(PTS, style=POINT, symbolsize=20);" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 243 "Later on, we'll want t o superimpose plots, so we assign this scatter-plot structure to a Map le variable we have named \"Scatter\" (note the \":\" at the end of th is command). We have to use the \"display\" command to see what \"S catter \"looks like" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "Scatter := plot(PTS, style=POINT, symbols ize=20):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "display(Scatter );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 348 "Here we have Maple do us the least-squares LINE for our data. \+ We've told Maple to return its result as an expression in variable x. This is DANGEROUS because x might already be in play. Try puttin g an assignment statement \"x := -13;\" in ahead of the following -- w atch the ensuing carnage. We should probably use some other variable name..." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "LSQ_line := LeastSquares(PTS, x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 75 "Now we plot the l east-squares line and store its plot in the variable \"PA\":" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "P A := plot(LSQ_line, x):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 113 "Now we use the paste-together aspect of \+ \"display\" to show the least-squares line in relation to the data po ints:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "display([Scatter, PA]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 174 "The above graph should d isappoint us as to how well the least-squares line fits the data. So \+ we try for a least-squares parabola by applying the \"curve=A*x^2+B*x+ C\" option: " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "LSQ_parabola := LeastSquares(PTS,x, curve=A*x^2+ B*x+C);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 247 "We don't have absolute freedom in what we can tell \"cur ve\" to do. In the following command, we supply a \"curve\" which we know to be a parabola. But parameter \"h\" will be squared, not \"li near\", so \"LeastSquares\" yarks at us, and refuses the job:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "LeastSquares(PTS,x, curve=A*(x-h)^2+k);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 110 "Here we plot the para bola and the data points as we did for the least-squares line. The pa rabola fits better:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "P_LSQ_parabola := plot(LSQ_parabola, x=1. .7):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "display([P_LSQ_para bola, Scatter]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 157 "We can interpolate in our table of values using o ur parabola. Our x-values are all integers. But, what if we neede d an idea about a y-value for x = 2.4?" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "Ex2_xRow;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "f := unapply(LSQ_parabola, x);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "Interpolated_Value := f(2.4) ;" }}}{EXCHG }{EXCHG }{EXCHG }{EXCHG }{EXCHG }{EXCHG }}{MARK "45" 0 } {VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }