{VERSION 2 3 "SGI IRIS UNIX" "2.3" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 0 0 0 0 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "" 2 6 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 2 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Output" 0 11 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 3 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Plot" 0 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {PARA 0 "" 0 "" {TEXT -1 174 "Let's now try to fit a cubic po lynomial to some data. Again, maple's built-in package can do this fo r us, but we like to work harder than we need to, so we understand mor e." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "Fir st, let's get some data, using the provided function" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "read(`/home/mat331/lsq_data`);" }}{PARA 6 "" 1 "" {TEXT -1 66 "defined line_pts(), quadratic_pts(), cubic_pts(), and cir cle_pts()" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "cubdata := cub ic_pts():" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "plot(cubdata,s tyle=point,axes=boxed);" }}{PARA 13 "" 1 "" {INLPLOT "6%-%'CURVESG6$77 7$$!1+++?emj?!#:$\"1+++Z7mZ:F*7$$!1+++g=Sm\")!#;$\"1+++\"*G)\\g%F07$$ \"1+++g%yAt\"F0$\"1+++ZOqZIF*7$$!1,++!p#R&y'F0$\"1+++x(e)H=F07$$\"1+++ +yTc>!#<$\"1++++r=w=F*7$$\"1+++x&GF*$\"1+++L#HZ:\"F*7$$\"1+++W'3dr# F*$\"1+++XwY/UF*7$$\"1+++h'oc#HF*$\"1+++@^#**H%F*7$$!1+++jkcT@F*$\"1++ +)>/Y)=F*7$$!1+++1#=+W\"F*$\"1+++t')30KF0-%'COLOURG6&%$RGBG$\"#5!\"\" \"\"!Fdr-%&STYLEG6#%&POINTG-%*AXESSTYLEG6#%$BOXG" 2 409 409 409 5 0 1 0 2 9 0 2 2 1.000000 45.000000 45.000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 57 "As in the linear case, we will do the wor k \"by hand\". " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 135 "To simplify typing, let's define the type of function we want to fit. We know (somehow) that our goal is to fit a cubic polyn omial, so" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "cub := (x,a,b,c,d) -> a*x^3 + b*x^2 + c*x + d;" }} {PARA 11 "" 1 "" {XPPMATH 20 "6#>%$cubG:6'%\"xG%\"aG%\"bG%\"cG%\"dG6\" 6$%)operatorG%&arrowGF,,**&9%\"\"\"9$\"\"$F3*&9&F3F4\"\"#F3*&9'F3F4F3F 39(F3F,F," }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 203 " Now we define an \"error functional\" which gives us the dist ance from our cubic to our data. Note that we use maple's \"nops\" c ommand so that we don't need to explicitly say how many points there a re. " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 115 " G := (a,b,c,d) -> sum((cub(cubdata[i][1],a,b,c,d) - cubdata[i][2] )^2, \+ i=1..nops(cubdata));" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#>%\"GG: 6&%\"aG%\"bG%\"cG%\"dG6\"6$%)operatorG%&arrowGF+-%$sumG6$*$,&-%$cubG6' &&%(cubdataG6#%\"iG6#\"\"\"9$9%9&9'F=&F86#\"\"#!\"\"FD/F;;F=-%%nopsG6# F9F+F+" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 85 "Now we just ask maple to find the (unique) critical point of G, wh ich is our minimum." }}{PARA 0 "" 0 "" {TEXT -1 68 "Since we used assi gn to set the coefficients, we won't see a result." }}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 184 "assign(solve( \{diff( G(a,b,c,d), a)=0,\n \+ diff( G(a,b,c,d), b)=0,\n diff( G(a,b,c,d), c)=0,\n diff( G(a,b,c,d), d)=0\},\n \{a,b, c,d\} ));" }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 42 "but we can readily see what the answer is:" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "cub(x,a,b,c,d);" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#,**$%\"xG\"\"$$!+-D.)o$!#5*$F%\"\"#$\"+\"\\/4#RF)F%$\"+tTFcE!\"* $\"+&[%3**>F0\"\"\"" }}}{PARA 0 "" 0 "" {TEXT -1 58 "Finally, lets mak e a picture, just to see how well it fits" }}{EXCHG {PARA 0 "> " 0 "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p$\"1,E\"G;N=u&F cp7$$!1****\\7*3=+&Fcp$\"1VX?>\"4r9)Fcp7$$!1)***\\PFcpPFcp$\"1xqtTVDt5 F-7$$!1)****\\7VQ[#Fcp$\"1x#=]7\\\"p8F-7$$!1)***\\i6:.8Fcp$\"1Vm6mkSg; F-7$$!1b+++v`hH!#=$\"1s`\"zF@7*>F-7$$\"1++](QIKH\"Fcp$\"1S-xgN=FfF-7$$\"1+]P\\`9Q>F-$\"1.%QAxA^$fF-7$$\"1+++!)RO+?F-$\"1da[ B_\\HfF-7$$\"1++D;:*R1#F-$\"1HzmmP:4fF-7$$\"1++]_!>w7#F-$\"1l.\"4t'\\t eF-7$$\"1++v)Q?QD#F-$\"1=ay!3>_v&F-7$$\"1+++5jypBF-$\"1e#**e$=i(e&F-7$ $\"1++]Ujp-DF-$\"1$p$fw+d@`F-7$$\"1+++gEd@EF-$\"1R?&oe?E,&F-7$$\"1++v3 '>$[FF-$\"1qtlvF.0YF-7$$\"1++D6EjpGF-$\"1M0$3Fhq$\"1++++r=w=F- 7$$\"1+++x&GF-$\"1+++L#HZ:\"F-7$$\"1+++W'3dr#F-$\"1+++XwY/UF-7$$ \"1+++h'oc#HF-$\"1+++@^#**H%F-7$$!1+++jkcT@F-$\"1+++)>/Y)=F-7$$!1+++1# =+W\"F-$\"1+++t')30KFcpFg^l-%&STYLEG6#%&POINTG-%+AXESLABELSG6$%\"xG%!G -%*AXESSTYLEG6#%$BOXG-%%VIEWG6$;F(Fc^l%(DEFAULTG" 2 409 409 409 2 0 1 0 2 9 0 2 2 1.000000 45.000000 45.000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 }}}{PARA 0 "" 0 "" {TEXT -1 0 "" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 94 "just for comparison, we can let ma ple do this for us using the built-in least-squares package:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 119 "fit[leastsquare[[x,y], y=A*x^3+B*x^2+C*x+D]]([[cub data[i][1]$i=1..nops(cubdata)],[cubdata[i][2] $i=1..nops(cubdata)]]); " }}{PARA 11 "" 1 "" {XPPMATH 20 "6#/%\"yG,**$%\"xG\"\"$$!+3D.)o$!#5*$ F'\"\"#$\"+0X!4#RF+F'$\"+xTFcE!\"*$\"+![%3**>F2\"\"\"" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "29 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 }