{VERSION 5 0 "IBM INTEL NT" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "Hyperlink" -1 17 "" 0 1 0 128 128 1 2 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 256 "" 0 10 0 0 0 0 1 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 257 "" 1 20 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "" 1 16 0 0 0 0 0 0 1 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 260 "" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 }{CSTYLE "" -1 261 "" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 0 } {CSTYLE "" -1 262 "" 1 16 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 263 "" 1 16 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 264 "" 1 16 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 265 "" 1 16 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 266 "" 1 16 0 0 0 0 0 0 1 0 0 0 0 0 0 0 } {CSTYLE "" -1 267 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 268 "" 1 16 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 269 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 270 "" 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 }{CSTYLE "" -1 271 "" 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 272 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 273 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 274 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 275 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 276 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 277 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 278 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 279 "" 0 1 0 0 0 0 0 2 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 280 "" 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 }{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 }{PSTYLE "Heading 1 " -1 3 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 4 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 2" -1 4 1 {CSTYLE "" -1 -1 "Times" 1 14 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 8 2 1 0 1 0 2 2 0 1 }{PSTYLE "Maple Output" -1 11 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 3 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Normal " -1 256 1 {CSTYLE "" -1 -1 "Helvetica" 1 14 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "AC - Title" -1 257 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 1 2 258 1 }{PSTYLE "AC - Note" -1 258 1 {CSTYLE "" -1 -1 "T imes" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 0 0 1 0 1 0 2 2 0 1 } {PSTYLE "AC - Normal Text" -1 259 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "AC - Se ction Heading" -1 260 1 {CSTYLE "" -1 -1 "Times" 1 16 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 12 0 1 0 1 0 2 2 260 1 }{PSTYLE "AC - Author" -1 261 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 1 2 2 2 2 2 1 1 1 1 }3 1 0 0 4 4 1 0 1 0 2 2 259 1 }{PSTYLE "Normal" -1 262 1 {CSTYLE "" -1 -1 "Times" 1 10 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "AC - Normal Text" -1 263 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 2 2 2 2 1 1 1 1 }3 1 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {PARA 257 "" 0 "" {TEXT 260 33 "Direct Method of Interpolation - " }{TEXT -1 10 "Simulation" }{TEXT 261 1 "." }{TEXT 257 0 "" }} {PARA 261 "" 0 "" {TEXT 256 7 "\251 2003 " }{TEXT -1 144 "Nathan Colli er, Autar Kaw, Jai Paul , Michael Keteltas, University of South Florid a , kaw@eng.usf.edu , http://numericalmethods.eng.usf.edu/mws " }} {PARA 258 "" 0 "" {TEXT -1 178 "NOTE: This worksheet demonstrates the \+ use of Maple to illustrate the direct method of interpolation. We lim it this worksheet to using first, second, and third order polynomials. " }}{SECT 0 {PARA 260 "" 0 "" {TEXT 258 12 "Introduction" }{TEXT -1 0 "" }}{PARA 259 "" 0 "" {TEXT 259 4 "The " }{URLLINK 17 "" 4 "http://nu mericalmethods.eng.usf.edu/mws/gen/05inp/mws_gen_inp_txt_direct.doc" " " }{TEXT 276 75 "direct method of interpolation (for detailed explanat ion, you can read the " }{URLLINK 17 "textbook notes and examples" 4 " http://numericalmethods.eng.usf.edu/mws/gen/05inp/mws_gen_inp_txt_dire ct.pdf" "" }{TEXT 278 12 ", and see a " }{URLLINK 17 "Power Point Pres entation)" 4 "http://numericalmethods.eng.usf.edu/mws/gen/05inp/mws_ge n_inp_ppt_direct.ppt" "" }{TEXT 277 27 " is based on the following." } }{PARA 259 "" 0 "" {TEXT 279 86 "Given 'n+1' data points of y vs. x fo rm, fit a polynomial of order 'n' as given below " }}{PARA 263 "" 0 " " {OLE 1 4104 1 "[xm]Br=WfoRrB:::wk;nyyI;G:;:j::>:B>N:F:nyyyyy]::yyyyy y::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::fyyyyya:nYf::G:jy;:::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::JcvGYMt>^:fBWMtNHm=;:::::::n:;`:Z@[::JjamlmJBil[Aj;JZQZ:B:F:YLpfF;J::::::::::OJ;@jyyyyyy;jysy; Z:::::::^<>:fB]mtFFcmnvGWMJnC==nHE=;:::::JJNZ:vyyuy:>:<::::::=J:^R>:F: AlqfG[maNFO=;::::::::_J;Zy=J:B::::::N:;B:G=;:wAK:AJ:nYf:n:v:J?>:w AS:UJ:n;;jA>:[B::a:c:e:gJ:nYvY:::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::j:b:B:::MFK]hQMw=]hQ[x=]hQyy=]hQOC> ]hQmD>]hQ;F>]hQYG>]hQOI>]pKAkbuOMDkbuOHJ;F]:>fCgAVRHjA@ZEFZ<>kjjBN[ZFZ>WdZfbk;>ZEB:Pnr:tlSZ::jbWfRFtX _uRFtXGeSFtXOtSFtXwcTFtX?uTFtXwyyuyA:C:=:yayQZ:J:JaM;wf:nk=j:F;Hj]AZ:N :s:;jD:;B:E:?R:=J:Z:JBAj:J @CB:=?R:=:?B:;B:yayA:<::::::C:[x:B:FZ:vCJ:< J::::::::::OZ:vYxI:;Z::::::JywYB:::::::::::::yay=J:B:::::::::::::::::: :jysy:>:<::::::::Dk;A`=:RFA>:KfFF;N@;b:AH>=J:L>:Cb:^D::J^w=>>:CB:f?=JZ:>is?;N@nyIF:;jj`Q>JSJiaj:> :k=N@^jBF:FFJSJwTj:Jv:_;OT;=:==N@>mL;ZaT XDpql`q?b:B:;CX=J>JSd:Ci==B:JSJvhj:<:Q;N@NgA FZ:jO:_;[C;=:Q;N@^g;FZ:>:uSXs:qAB:>LB:Cb:^DP@::v=>>:;B:Cb::::jIJJ:B:f?;J;b<;j^`j :Zh:d:gY;=:]cEK:_;mt:=:[cEO:G;OjywyyI:>:s:qQBv::Uk:^:>X;j;:B>N:F:nyyyyy]::yyyyyy:::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::fyyyyya:nYf::G:jy ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::JcvGYMt>^:fBWMtNHm=;:::::::n:;`:Z@[::J:=Vmm JBil[Aj;Z>Z:j:vCSmlJ::::::::::OJ;@jyyyyyy;jysy;Z:::::::^<>:fB]mtFFcmnv GWMJnC==nHE=;:::::JJNZ:vyyuy:>:<::::::=J:nJ>:F:AlqfG[maNFO=;::::::::_J ;Zy=J:B::::::N:;B:G=;:wAK:AJ:nYf:n:v::M:wAQ:S:UJ:n;v;;JB]JG<==]J?DJ;m\\LVj[;=Jyyy;d:yayQZHQ:>:;`:Z@wZFZ>WdZfbk;>ZEZ?GHZhV`:^xsNpkC:;B::j;<:=:U:aC:>l;Z:jysyA:C:=:yay QZ:J:jLa:qe:Nk:Mb:>Z:f:NZ;F:;B:E:=b:yyyyI:E:WS:k:E: Qb:B:E:Sb:;d:;H<_:Gc;YJGvyyuy;B:[B:l;F:@CB:f_;J>B:_c<;Y:EB<=Z:ngsO:YLpJbNHEms>@[;;B:::::::JF:yayA: <::::::C:Sh:B:FZ:vCJ::<::::::::hj:RFF: Dk;u@]J:^Z<:::J^w=>>:CB:f?=J;N@;V:;t;= J:JSJJDj:L;Z:^Z>Z:B:f?;J d=N;^_hn_hn?BEK:_;[V:=J:B:>LB:Cb::::jIJJ:B:f?=J:s:qQBv:pbQ;B:bK;J:<:^cGgbG?pva<>:j F^;>:;d:SB:;d:>:;:::::::::::::::::::::::::^C:>:J;V>>:KV:SJ>A:qjLR:SJlq kGXQFtkGXQFZ::>uwa<>:;woOJFAJ@^hYQ;?BCkyW::J hpkGXQfqYD^lWV=JntYD^jWV=cUA^d;W]q_b;W==Z:T:>gxM:>:jK]o;fe`GxeF: " 0 "" {MPLTEXT 1 0 8 "restart;" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "with(LinearAlgebra):\nwith (linalg):" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT 262 23 "Section I : Input Data." }{TEXT -1 0 "" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 93 "The follo wing is the array of x-y data which is used to interpolate. It is obta ined from the " }{URLLINK 17 "physical problem" 4 "http://numericalmet hods.eng.usf.edu/mws/gen/05inp/mws_gen_inp_phy_problem.pdf" "" }{TEXT -1 131 " of velocity of rocket (y-values) vs. time (x-values) data. \+ We are asked to find the velocity at an intermediate point of x=16. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 80 "xy:=[[10.,227.04],[0.,0 .],[20.,517.35],[15.,362.78],[30.,901.67],[22.5,602.97]]:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 32 "Value of X at which Y is desired" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "xdesired:=16:" }}}{PARA 11 " " 1 "" {TEXT -1 0 "" }}}{PARA 3 "" 0 "" {TEXT -1 0 "" }}{SECT 0 {PARA 3 "" 0 "" {TEXT 263 33 "Section II : Big scary functions." }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "n:=ro wdim(xy):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 58 "for i from 1 t o n do\nx[i]:=xy[i,1];\ny[i]:=xy[i,2];\nend do:" }{TEXT -1 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 575 "T he following function considers the x data and selects those data poin ts which are close to the desired x value. The closeness is based on \+ the least absolute difference between the x data values and the desire d x value. This function selects the two closest data points that b racket the desired value of x. It first picks the closest data point t o the desired x value. It then checks if this value is less than or gr eater than the desired value. If it is less, then, it selects the dat a point which is greater than the desired value and also the closest, \+ and viceversa." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 75 "Finds the absolute difference between the X values a nd the desired X value." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 58 "for i fr om 1 to n do\n co[i]:=abs(x[i]-xdesired);\nend do:\n" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 58 "Identifies the X value with the least a bsolute difference." }{MPLTEXT 1 0 95 "\nc:=co[1]:\nfor i from 2 to n \+ do\n if c > co[i] then\n c:=co[i];\n ci:=i;\n end if:\nend do: \n" }}{PARA 0 "" 0 "" {TEXT -1 179 "If the value with the least absolu te difference is less than the desired value, then it selects the clos est data point greater than the desired value to bracket the desired v alue." }{MPLTEXT 1 0 1 "\n" }{TEXT -1 0 "" }{MPLTEXT 1 0 316 "if x[ci] < xdesired then\n q:=1;\n for i from 1 to n do\n if x[i] > xdesi red then\n nex[q]:=x[i];\n q:=q+1;\n end if;\n end do;\n \n b:=nex[1]:\n for i from 2 to q-1 do\n if b > nex[i] then\n \+ b:=nex[i];\n end if:\n end do:\n\n for i from 1 to n do\n if x[i]=b then bi:=i end if;\n end do;\nend if:\n" }}{PARA 0 "" 0 "" {TEXT -1 179 "If the value with the least absolute difference is great er than the desired value, then it selects the closest data point less than the desired value to bracket the desired value." }{MPLTEXT 1 0 1 "\n" }{TEXT -1 0 "" }{MPLTEXT 1 0 335 "if x[ci] > xdesired then\n q :=1;\n for i from 1 to n do\n if x[i] < xdesired then\n nex[q ]:=x[i];\n q:=q+1;\n end if;\n end do;\n\n b:=nex[1]:\n for i from 2 to q-1 do\n if b < nex[i] then\n b:=nex[i];\n end if:\n end do:\n\n for i from 1 to n do\n if x[i]=b then bi:=i en d if;\n end do;\nend if:\n\nfirsttwo:=:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 317 "If more than two va lues are desired, the same procedure as above is followed to choose th e 2 data points which bracket the desired value. In addition, the foll owing function selects the subsequent values that are closest to the d esired value and puts all the values into a matrix, maintaining the or iginal data order." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 959 "for i from 1 to n do\n A[i,2]:=i;\n A[i, 1]:=co[i];\nend do:\n\nfor passnum from 1 to n-1 do\n for i from 1 to n-passnum do\n if A[i,1]>A[i+1,1] then\n temp1:=A[i,1];\n \+ temp2:=A[i,2];\n A[i,1]:=A[i+1,1];\n A[i,2]:=A[i+1,2];\n \+ A[i+1,1]:=temp1;\n A[i+1,2]:=temp2;\n end if:\n end do:\n end do:\n\nfor i from 1 to n do\n A[i,3]:=i;\nend do:\n\nfor passnum \+ from 1 to n-1 do\n for i from 1 to n-passnum do\n if A[i,2]>A[i+1, 2] then\n temp1:=A[i,1];\n temp2:=A[i,2];\n temp3:=A[i, 3];\n A[i,1]:=A[i+1,1];\n A[i,2]:=A[i+1,2];\n A[i,3]:=A [i+1,3];\n A[i+1,1]:=temp1;\n A[i+1,2]:=temp2;\n A[i+1, 3]:=temp3;\n end if:\n end do:\nend do:\n\nfor i from 1 to n do\n \+ d[i]:=A[i,3];\nend do:\n\nif d[firsttwo[2]]<>2 then\n temp:=d[firstt wo[2]];\n d[firsttwo[2]]:=1;\n for i from 1 to n do\n if i <> fir sttwo[1] and i <> firsttwo[2] and d[i] <= temp then\n d[i]:=d[i] +1;\n end if:\n end do;\n d[firsttwo[1]]:=1;\nend if:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 212 "ranger:=proc(ar,n)\nlocal i,xmin,x max,xrange;\nxmin:=ar[1]:\nxmax:=ar[1]:\nfor i from 1 to n do\nif ar[i ] > xmax then xmax:=ar[i] end if;\nif ar[i] < xmin then xmin:=ar[i] en d if;\nend do;\nxrange:=xmin..xmax;\nend proc: " }{TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 37 "Plotting \+ the given values of X and Y." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 72 "plot(xy,ranger(x,n),style=POINT,color=BLU E,symbol=CIRCLE,symbolsize=30);" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT 264 34 "Section III: Linear Interpolation." }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 75 "The two closest data points to the desired value are chos en in this method." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "datap oints:=2:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 109 "p:=1:\nfor i \+ from 1 to n do\nif d[i] <= datapoints then\nxdata[p]:=x[i];\nydata[p]: =y[i];\np:=p+1;\nend if\nend do:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "entries(xdata);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "entries(ydata);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 71 "We then set up equations to find c oefficients of the linear interpolant" }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "M:=[[1,xdata[1]],[1,xda ta[2]]];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "m:=inverse(M); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 47 "The Coefficients of the linear interpolant are," }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 39 "a:=evalm( m &* [[ydata[1]],[ydata[2]]]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 49 "Hence, the equation of the linear interpolant is," }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 28 "flinear(z):=a[1,1]+a[2,1]*z;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 110 "Substituting the value of the desired X value for z in the above equation, the corresponding Y value is found." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "eval(flinear(z),z=xdesired);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "fprev:=%:" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 68 "Plotting the Linear int erpolant and the value of Y for the desired X" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 247 "plot([[t,eval(flin ear(z),z=t),t=ranger(xdata,datapoints)],xy,[[xdesired,eval(flinear(z), z=xdesired)]]],z=ranger(x,n),style=[LINE,POINT,POINT],color=[RED,BLUE, BLUE],symbol=[CROSS,CIRCLE],symbolsize=[40,30],thickness=3,title=\"Lin ear interpolation\");" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT 265 61 "Secti on IV: Quadratic Interpolation (Second order polynomial)" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 77 "The three closest data points to the desi red value are chosen in this method." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "datapoints:=3:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 109 "p:=1:\nfor i from 1 to n do\nif d[i] <= datapoints then\nxdat a[p]:=x[i];\nydata[p]:=y[i];\np:=p+1;\nend if\nend do:\n" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "entries(xdata);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "entries(ydata);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 74 "We then set up equations \+ to find coefficients of the quadratic interpolant" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 83 "M:=[[1,xdat a[1],(xdata[1])^2],[1,xdata[2],(xdata[2])^2],[1,xdata[3],(xdata[3])^2] ];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "m:=inverse(M);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 46 "The coefficients of quadratic inte rpolant are," }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "a:=evalm(m \+ &* [[ydata[1]],[ydata[2]],[ydata[3]]]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 52 "Hence, the equation of th e quadratic interpolant is," }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "fqua d(z):=a[1,1]+a[2,1]*z+a[3,1]*z^2;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 110 "Substituting the value of the desired X value for z in the above \+ equation, the corresponding Y value is found." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "eval(fquad(z),z=xdesired);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "fnew:=%:" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 119 "The absolute percentage relative \+ approximate error between the first order and the second order interpo lation values is" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "epsilon :=abs((fnew-fprev)/fnew)*100;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 68 " The number of significant digits at least correct in the solution is" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "sigdig:=floor(2-log10(eps ilon/0.5));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "fprev:=fnew: " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 71 "Plotting the quadratic interpolant and the value of Y for the desi red X" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 246 "plot([[t,eval(fquad(z),z=t),t=ranger(xdata,datapoints)],xy,[[xd esired,eval(fquad(z),z=xdesired)]]],z=ranger(x,n),style=[LINE,POINT,PO INT],color=[RED,BLUE,BLUE],symbol=[CROSS,CIRCLE],symbolsize=[40,30],th ickness=3,title=\"Quadratic interpolation\");" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT 266 55 "Section V: Cubic Interpolation (Third order polynom ial)" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 76 "The four closest data poin ts to the desired value are chosen in this method." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "datapoints:=4:" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 109 "p:=1:\nfor i from 1 to n do\nif d[i] <= datapoints then\nxdata[p]:=x[i];\nydata[p]:=y[i];\np:=p+1;\nend if\nend do:\n" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "entries(xdata);" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "entries(ydata);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 70 "We then s et up equations to find coefficients of the cubic interpolant" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 161 "M:=[[1,xdata[1],(xdata[1])^2,(xdata[1])^3],[1,xdata[2],(xdata[2 ])^2,(xdata[2])^3],[1,xdata[3],(xdata[3])^2,(xdata[3])^3],[1,xdata[4], (xdata[4])^2,(xdata[4])^3]];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "m:=inverse(M);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 42 "The coeff icients of cubic interpolant are," }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "a:=evalm(m &* [[ydata[1]],[ydata[2]],[ydata[3]],[ydat a[4]]]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 48 "Hence, the equation of the cubic interpolant is," }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "fcubic(z):=a[1,1]+a[2,1]*z+a[3,1]*z ^2+a[4,1]*z^3;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 110 "Substituting t he value of the desired X value for z in the above equation, the corre sponding Y value is found." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "eval( fcubic(z),z=xdesired);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "fn ew:=%:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 112 "The absolute percentag e relative approximate error between the second order and the third or der interpolation is" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "eps ilon:=abs((fnew-fprev)/fnew)*100;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 68 "the number of significant digits at least correct in the solution \+ is" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "sigdig:=floor(2-log10 (epsilon/0.5));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 67 "Plotting the cubic interpolant and the value of Y fo r the desired X" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 244 "plot([[t,eval(fcubic(z),z=t),t=ranger(xdata,datapoin ts)],xy,[[xdesired,eval(fcubic(z),z=xdesired)]]],z=ranger(x,n),style=[ LINE,POINT,POINT],color=[RED,BLUE,BLUE],symbol=[CROSS,CIRCLE],symbolsi ze=[40,30],thickness=3,title=\"Cubic interpolation\");" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 0 "" }{TEXT 267 0 "" }{TEXT 268 23 "Section VI: Conclusion." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 279 "Maple helped us to apply our knowledge of numerical methods of interpolation to find the value of y at a particular value of x using first, second, and third order \+ direct method of interpolation. Using Maple functions and plotting rou tines made it easy to illustrate this method." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{PARA 4 "" 0 "" {TEXT 270 10 "References" }}{PARA 0 " " 0 "" {TEXT -1 4 "[1] " }{TEXT 272 174 "Nathan Collier, Autar Kaw, Ja i Paul , Michael Keteltas, Holistic Numerical Methods Institute, See h ttp://numericalmethods.eng.usf.edu/mws/gen/05inp/mws_gen_inp_sim_direc t.mws" }}{PARA 0 "" 0 "" {TEXT 280 76 "http://numericalmethods.eng.usf .edu/mws/gen/05inp/mws_gen_inp_txt_direct.pdf" }{TEXT -1 0 "" }}{PARA 262 "" 0 "" {TEXT -1 0 "" }}{PARA 262 "" 0 "" {TEXT 269 10 "Disclaimer " }{TEXT 271 1 ":" }{TEXT -1 248 " While every effort has been made to validate the solutions in this worksheet, University of South Florida and the contributors are not responsible for any errors contained and are not liable for any damages resulting from the use of this materia l." }}}{MARK "13 0" 76 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 } {PAGENUMBERS 0 1 2 33 1 1 }