{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 "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Output" 2 20 "" 0 1 0 0 255 1 0 0 0 0 0 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 }{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 "Maple Plot" -1 13 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 } {PSTYLE "Title" -1 18 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }3 1 0 0 12 12 1 0 1 0 2 2 19 1 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 45 "M246 - Lab 2 - Curve fitt ing by Least Squares" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "wit h(linalg): with(plots): " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 54 "N:=10: X:=matrix(1,N): Y:=matrix(N,1): A:=matrix(4,N):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 32 "Compute t he data points [xi,yi]:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 " k:=9: T:=0.4:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 90 "for i from 1 to N do X[1,i]:=-0.5+1.5*i/N; Y[i,1]:=-X[1,i]+1.0/(1.0+exp(-k*X[1,i ]+T)); od:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 34 "Define the K functi ons to be used:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "f[1]:=x- >1.0: f[2]:=x->x: f[3]:=x->x^2: f[4]:=x->x^3:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 58 "Set up the K x N matrix A, and compute B=A x (A transp ose)" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "for i from 1 to N d o x:=X[1,i];" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 22 " for j from 1 to 4 do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 28 " A[j,i]:=f[j](x); od; od: " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "B:=multiply(A,transpose (A)):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "det(B); Q:=inverse (B):" }}{PARA 11 "" 1 "" {XPPMATH 20 "6#$\"+rGrX " 0 "" {MPLTEXT 1 0 34 "V:=matrix(4,1): V:=multiply(A,Y):" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 59 "a:=multiply(Q,V): print(`coe ffs. of cubic =`,transpose(a));" }}{PARA 11 "" 1 "" {XPPMATH 20 "6$%3c oeffs.~of~cubic~=G-%'matrixG6#7#7&$\"+VR$fe%!#5$\"+ES1#e$F+$!*qw$GO!\" *$!*%[TH]F0" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 82 "G1:=plot(a[1 ,1]+a[2,1]*t+a[3,1]*t^2+a[4,1]*t^3,t=-0.5..1,color=GREEN,thickness=2): " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 59 "L:=[]: for i from 1 to \+ N do L:=[op(L),[X[1,i],Y[i,1]]]; od:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "G2:=pointplot(L,symbol=CIRCLE,symbolsize=14,color=BLA CK):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 109 "display(G1,G2,titl e=cat(`Best fit cubic to x,y data with k=`,convert(k,string),` theta=` ,convert(T,string)));" }}{PARA 13 "" 1 "" {GLPLOT2D 449 177 177 {PLOTDATA 2 "6'-%'CURVESG6%7U7$$!3++++++++]!#=$\"3!*******4Y[;DF*7$$!3 u****\\(oUIn%F*$\"3&=@)4J^\"Hj#F*7$$!37+]7y)e&)Q%F*$\"3H0Q/-5@SFF*7$$! 3G++D\"3F'oSF*$\"3q)pMp$*Hm'GF*7$$!3i***\\(oXdYPF*$\"3!o?V86v!**HF*7$$ !3!)**\\i:F0EMF*$\"3zA2.@@1NJF*7$$!3Q+]7Gz))GJF*$\"3iVp$)3&*)RE$F*7$$! 3#)**\\7.5>@GF*$\"3[Ioo6*4&*R$F*7$$!3(***\\7./(H]#F*$\"3\"ei'\\@i!4a$F *7$$!35+]iS.x&=#F*$\"3CpODV([@o$F*7$$!3!)****\\(3\"\\f=F*$\"3To?g$pIn# QF*7$$!3'****\\P9/@d\"F*$\"33k0U&3iE&RF*7$$!3u****\\7Xd[7F*$\"3/Y-t6> \">4%F*7$$!3)4++]PkrB*!#>$\"3I'390gd!GUF*7$$!3h(****\\([b1hFfo$\"3%z') e?G3[N%F*7$$!3e++DJ:mjKFfo$\"3W-4ctvLlWF*7$$\"3+2++]i8o6!#?$\"3Ym$[FK8 ,f%F*7$$\"3m++++&>0)HFfo$\"3)G\\FmiT$*o%F*7$$\"3.***\\(=-p6jFfo$\"3Q\" fJCg.jz%F*7$$\"3o&*****\\2Mg#*Ffo$\"3Ckbp&F*7$$\"3y** \\7yG>6JF*$\"39Iw&Gb8x>&F*7$$\"3K++voo6AMF*$\"3AixwQUG&=&F*7$$\"3Z**** *\\xJLu$F*$\"3;;wWo6ea^F*7$$\"3c***\\P*yddSF*$\"3>$*p$y.Fg5&F*7$$\"3#* **\\(=u\"yF2/&F*7$$\"3y***\\i0A#*p%F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