{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 Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" -1 256 "Helvetica" 1 14 128 0 0 1 0 0 2 0 0 0 0 0 0 1 } {CSTYLE "" -1 257 "" 0 24 0 0 255 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 258 "Helvetica" 0 1 128 0 0 1 0 0 0 0 0 0 0 0 0 1 }{CSTYLE "" -1 259 "" 0 1 255 0 0 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 260 "" 0 1 0 0 128 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 261 "" 0 1 0 0 128 1 0 0 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 262 "" 1 12 0 0 0 0 0 1 0 0 0 0 0 0 0 0 } {CSTYLE "" -1 278 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 279 "" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 280 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 281 "" 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 }{CSTYLE "" -1 282 "" 0 1 0 0 0 0 0 1 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 "Title" -1 256 1 {CSTYLE "" -1 -1 "Times" 1 18 0 0 0 1 2 1 1 2 2 2 1 1 1 1 }1 1 0 0 12 12 1 0 1 0 2 2 19 1 } {PSTYLE "Author" -1 257 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 8 8 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 258 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 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Title" -1 259 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 2 2 19 1 } {PSTYLE "Author" -1 260 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 2 1 2 2 2 1 1 1 1 }3 1 0 0 8 8 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 261 1 {CSTYLE "" -1 -1 "Courier" 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 "Normal" -1 262 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 "Normal" -1 263 1 {CSTYLE "" -1 -1 "Times" 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 "Normal" -1 264 1 {CSTYLE "" -1 -1 "Courier" 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 2" -1 265 1 {CSTYLE "" -1 -1 "Ti mes" 1 12 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 }} {SECT 0 {EXCHG {PARA 256 "" 0 "" {TEXT 257 30 "MLC Lab Visit - Lab 06 \+ - Maple" }}{PARA 0 "" 0 "" {TEXT 256 46 "Mth 355 (a.k.a. Mth 399) Feb \+ 12, 2003 Maple 7" }{TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 258 16 "Bent E. Petersen" }{TEXT -1 0 "" }}{PARA 264 "" 0 "" {TEXT 260 0 "" }} {PARA 264 "" 0 "" {TEXT 261 22 "petersen@math.orst.edu" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 263 "" 0 "" {TEXT 259 181 "There are 3 prob lems below. Problem solutions are due Feb 19, 2003. Email your solutio ns to me as Maple worksheet attachments. Your worksheet must execute c orrectly for full credit." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 74 "In this week's lab we investigate a few randomly c hosen features of Maple." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 17 "Partial Fractions" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }{TEXT 262 0 "" }}{PARA 0 "" 0 "" {TEXT -1 84 "Partial fraction deco mposition in Maple is carried out with the convert() command." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "f:=(3*x^2-2*x+7)/( (x^2+1)*(x-3)^3*(x^2+x-1) );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "convert(f,parfrac,x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 367 "Note sin ce all the coefficients here are rational, Maple attempts the expansio n over the rational numbers. This is the reason the last term is not w hat you were led to expect in calculus since x^2+x-1 does factor over \+ the rationals. We can force a factorization by telling Maple to use th e extension field of the rationals obtained by appending the square ro ot of 5." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 29 "convert(f,parfrac,x,sqrt(5));" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 219 "This expression s hould agree with what you learned in calculus, but it is inconvenient, and not really general, to have to specifiy the radicals to append. A more general and more convenient procedure is to use RootOf::" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "h:=convert(f,parfrac,x,RootOf(x^2+x-1));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 203 "Cool, but not very \+ familiar. We need to evaluate the RootOf() expressions. This may be do ne with the allvalues() command, but it will evaluate the full express ion for each root (and so give us 2 copies):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "allvalues(h);" }} }{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 57 "A s expected we got 2 copies of the answer. Just pick one:" }}{PARA 0 " " 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "allv alues(h)[1];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 134 "We can also request that Maple perform the factorizati on over the real numbers. In this case Maple will use floating point a rithmetic." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 26 "convert(f,parfrac,x,real);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 57 "You can make a rationa l approximation in the obvious way:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 44 "convert(convert(f,parfrac, x,real),rational);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 28 "Let's look at complex roots:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "g:=( (2*x^3 -x-1)/((x^2+2*x+5)^2*(x^2-1)) );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "convert(g,parfrac,x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 85 "Exactly what we expected! Of course we may prefer to expand over the complex numbers:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "c onvert(g,parfrac,x,complex);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 88 "Hmm. We got a floating point expansion. We can convert to rational numbers in this case:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "convert(con vert(g,parfrac,x,complex),rational);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 177 "That looks alright here, but s ometimes the conversion from floating point to rational numbers will i ntroduce errors in the final expression. It's safer to make use of Roo tsOf()." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "allvalues(convert(g,parfrac,x,RootOf(x^2+2*x+5)))[1]; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 138 "Another way, perhaps the best way, to handle rational complex roo ts is to specify our extension field as 'sqrt(-1)' rather than 'comple x'." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 30 "convert(g,parfrac,x,sqrt(-1));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 263 "" 0 "" {TEXT -1 0 "" }{TEXT 278 24 "A \+ more ambitious example" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 202 "The partial fraction expansion facility is not limi ted to simple examples, but one pretty well has to use floating point, or a mixture of floating point and rational arithmetic, except in spe cial cases." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "p:=x^9+5*x^8+10*x^7+20*x^6+24*x^5-x^4+16;" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "convert(1/p,parfrac,x);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 58 "Fr om our expeience above we know the problem here is that " }{XPPEDIT 18 0 "x^6+3*x^5-x+2;" "6#,**$)%\"xG\"\"'\"\"\"F(*&\"\"$F()F&\"\"&F(F(F &!\"\"\"\"#F(" }{TEXT -1 55 " is irreducible over the rationals. We ca n try RootOf(" }{XPPEDIT 18 0 "x^6+3*x^5-x+2;" "6#,**$)%\"xG\"\"'\"\" \"F(*&\"\"$F()F&\"\"&F(F(F&!\"\"\"\"#F(" }{TEXT -1 259 ") as our exte nsion field, but we only obtain a result which is not very satisfactor y as a final result, though it may be useful for further calculation. \+ The best thing to do probably, is to use floating point, real or compl ex according to our needs or taste." }}{PARA 0 "" 0 "" {TEXT -1 0 "" } }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "cr:=convert(1/p,parfrac,x, real);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 35 "cf:=convert(1/p,p arfrac,x,complex);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 137 "The very small imaginary parts are due to roundo ff (the corresponding terms should be real). Let's eliminate these sma ll imaginary parts:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "subs(seq(op(cf)[k]=evalc(Re(op(cf)[k])),k =1..3),cf);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 67 "Another approach is to split off the terms we can evalu ate exactly:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 37 "c2f:=convert(1/p,parfrac,x,sqrt(-1));" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 111 "N ote using 'sqrt(-1)' rather than 'complex' forces Maple to use rationa l arithmetic rather than floating point." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "c2p:=op(c2f)[4];" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "c3f:=convert(c2p,parfrac,x, complex);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 60 "c4f:=subs(seq( op(c3f)[k]=evalc(Re(op(c3f)[k])),k=1..2),c3f);" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 " sum(op(c2f)[k],k=1..3)+evalf(c4f,6);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 45 "Not exact perhaps, but it is a \+ useful result." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}} {SECT 1 {PARA 3 "" 0 "" {TEXT -1 22 "Full Partial Fractions" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 256 "The fullparfrac facility performs a partial fraction decomposition of a rational expression in one variable after completely factoring the denominator into linear f actors over its splitting field. As you might expect, the RootsOf() ex pression occurs often." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "p:=x^9+5*x^8+10*x^7+20*x^6+24*x^5-x ^4+16;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "cp:=convert(1/p,f ullparfrac,x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 88 "We can evaluate the first sum here, but there is not much we can do with the second one." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 27 "convert(op(cp)[2],radical );" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 152 "In the case of denominators that are cubic, Maple can actually find the partial fraction expansion in radical form (though you may n ot like the answer):" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "p2:=x^3-4*x^2+7*x+3;" }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 43 "cp2:=convert((x^2-2*x+4)/p2,fullparfrac,x); " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 113 "The RootsOf() expression is brief and very clear, but let's req uest an expression in terms of the actual roots:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "convert(cp2 ,radical);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 25 "Trigonometric Expressions" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 120 "The procedures convert() and combine() may be used to manipulate trigonometric expressions (an d much else - check help)." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 36 "ex1:=sin(2*x): ex1=convert(ex1,tan) ;" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "ex1=convert(ex1,exp); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 53 "ex2:=tan(x)*sec(2*x)+se c(x): ex2=convert(ex2,sincos);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "ex2=simplify(convert(ex2,tan));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "ex2=simplify(convert(ex2,exp)); " }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 173 "The combine() pro cedure combines terms as you might expect, but it also may be used to \+ obtain Fourier sum expansions (Fourier series if you like) of trigonom etric functions." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "ex3:=Sum(cos(x)^k,k=1..4): ex3=combine(value( ex3));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "ex4:=Sum(sin(x)^k ,k=1..4): ex4=combine(value(ex4));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "ex5:=cos(3*x)*sin(2*x)^2: ex5=combine(ex5);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 157 "M aple has a builtin database of trigonometric identies. We can consult \+ the database by means of the trigsubs() procedure. (We can do much mor e - check help.)" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "trigsubs(sin(2*x)*cos(x));" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "trigsubs(cos(x));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT 279 21 "Comments on combine ()" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 57 "We \+ can use combine() to combine terms of course. Consider" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "combin e(sqrt(x)*sqrt(y));" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 154 "Here Maple refuses the obvious simplification \+ because it is not always correct. However, we can force it by passing \+ the symbolic instruction to combine()." }}{PARA 0 "" 0 "" {TEXT -1 0 " " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 34 "combine(sqrt(x)*sqrt(y) ,symbolic);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 " " {TEXT -1 75 "If you make use of such \"simplifications\" then you wi ll have to be careful." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 25 "Least Squares Fit (stats)" }} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 223 "The stats package provides a very convenient way to do least squares fitting in Maple. \+ Actually we only need the subpackage fit. The subpackage statplots is \+ also handy, though sometimes the package plots is more convenient." }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 247 "We can a lso use the leastsqrs() procedure in the linalg package to do leastsqu ares fitting, but we would have to a bit more work since we first have to express our problem as a system of linear equations. The stats pac kage handles all this for us." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "with(stats): with(plots):" } }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 258 "In statistical applications the re is often much data. You certainly do not want to type it all into y our worksheet. Check help for the procedure importdata() to see one wa y to get data from a file. We will not need this procedure for our sma ll examples here." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 17 "Here's some data:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "Xdata:=[1.0,2.0,3.0,4.0,5.0, 6.0,7.0,8.0,9.0];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "Ydata: =[2.33,0.0626,-2.16,-2.45,-.357,2.21,2.75,0.636,-2.45];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 88 "We need a list of data point for the plot() procedure. We can obtain such a lis t easily:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 50 "data:=[seq([Xdata[k],Ydata[k]],k=1..nops(Xdata))]; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 59 "Let's plot the data points and save the plot for later use:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 72 "dataplot:=plot(data,style=point,symbol=circle,symbolsize=16,colo r=blue):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 121 "Let's assume we have some good reason to suppose that ou r data points should satisy the following trigonometric relation:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "eqn:=y=a+b*cos(x)+c*sin(x)+d*cos(2*x)+e*sin(2*x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 67 "The five \+ coefficients are to be determined. They are our variables." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "var s:=\{a,b,c,d,e\};" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 " " 0 "" {TEXT -1 403 "We are ready to ask Maple for the coefficients. N ote I used floating point data in Xdata above, even though the values \+ are integers. This is important. If I had used Xdata:=\{1,2,..] instea d then Maple would do symbolic calculations involving expressions sin( 1), cos(1), sin(2), and so on, for at least part of the calculation. T he result would be that fiteqn would take much longer to calculate. Tr y it." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 56 "fiteqn:=fit[leastsquare[[x,y],eqn,vars]]([Xdata,Ydata ]);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 87 "Let's plot the calculated least squares fit and then display it with the original data:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 57 "fitplot:=plot(rhs(fiteqn),x=0..10,c olor=red,thickness=2):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "d isplay(\{dataplot,fitplot\});" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 " " }}{PARA 0 "" 0 "" {TEXT -1 155 "It is a nice fit! But do note, all t his would be meaningless unless we have some good reason to expect the functional relation eqn is correct for our data." }}}{EXCHG {PARA 0 " > " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 26 "Le ast Squares Fit (linalg)" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "r estart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 105 "Let's consider the same problem as in the previous secti on, but this time we will use the linalg package." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 13 "with(linalg ):" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "Xdata:=[1.0,2.0,3.0,4 .0,5.0,6.0,7.0,8.0,9.0];" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "Ydata:=[2.33,0.0626,-2.16,-2.45,-.357,2.21,2.75,0.636,-2.45];" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 28 "He re's our model, as before:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "eqn:=y=a+b*cos(x)+c*sin(x)+d*cos(2* x)+e*sin(2*x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 102 "Now we find the linear equations that the coefficie nts should satisfy (approximately) by substitution:" }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 78 "for k fro m 1 to nops(Xdata) do lineqn[k]:=subs(x=Xdata[k],y=Ydata[k],eqn); od: " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 36 "Then we put the equations in a list:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 40 "eqns:=[seq(lineqn[k] ,k=1..nops(Xdata))];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 354 "Once we have a list of linear equations we can ask Maple to compute the coefficient matrix by means of the procedure genmatrix(). Note that we have to specify the unknowns in a list. It is easy enough to extract the inhomogeneous term by hand, but the gen matrix() procedure will do that as well if we provide an optional thir d parameter to assign it to." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "A:=genmatrix(eqns,[a,b,c,d,e ],b);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "evalm(b);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 66 "As you might expect the system of equations above is inconsistent:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "linsolve(A,b);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 176 "Maple indicates the lack of a solution by retu rning an empty response. For the approximate solution that is best in \+ the sense of least squares we use the leastsqrs() procedure." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "leastsqrs(A,ihterm);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 77 "These coe fficients are the same as the ones obtained in the previous section." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 6 "Limits" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "re start;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 97 "Maple is capable of computing a few limits. Note the iner t form Limit() of the limit() procedure." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "limit(sin(x)/tan(x), x=0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 55 "We can play the usual game to format the result nicely:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 47 "Limit((cos(x)-1+x^2/2)*x^(-4),x=0): %=value(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 27 "Here are \+ some more example:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "limit(1/x^2,x=infinity);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "limit(x^x,x=0);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "limit(sin(1/x),x=0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 134 "That is a curious result . Instead of saying that the limit does not exist Maple returns a rang e consisting of all of the limit points." }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "limit(x*sin(1/x),x=0 );" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "limit((1+sin(x))^(1/x ),x=0);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 26 "limit(cos(x)^(1/ x^2),x=0);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 39 "Maple can also handle one-sided limits." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 43 "Limit(sin (x)^(1/sin(x)^5),x=0): %=value(%);" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 49 "Limit(sin(x)^(1/sin(x)^5),x=0,right): %=value(%);" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "Limit(sin(x)^(1/sin(x)^5),x =0,left): %=value(%);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 51 "Maple knows about some pretty sophisticat ed limits:" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 54 "Limit(Sum(1/k,k=1..n)-log(n),n=infinity): %=value(% ); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "'gamma'=evalf(gamma, 60);" }}}}{SECT 1 {PARA 3 "" 0 "" {TEXT -1 8 "Problems" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 92 "You may have to load some libraries to do some of the problems. That's part of the problems!" } }{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 280 9 " Problem 1" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 27 "Expand in partial fractions" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "expr1:=(2*x-3)/((x+b)*(x+1)) ;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 79 "What happens when b = 1? F ind the limit as b goes to 1 for your expansion." }}{PARA 0 "" 0 " " {TEXT -1 0 "" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 281 9 "Problem 2" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 36 "Find the \+ Fourier series expansion of" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "expr2:=cos(x)*cos(3*x)*cos(5 *x)*cos(7*x)*cos(9*x);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT 282 9 "Problem 3" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 64 "Her e's the human population p(t) of the Earth for a few years:" }} {PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 717 "DataPoints := [ [1900,1650],[1910,1750],[1920,1860],[1930,2070] ,[1940,2300],[1950,2555],[1951,2593],[1952,2635],[1953,2680],[1954,272 8],[1955, 2780],[1956,2833],[1957,2888],[1958,2945],[1959,2997],[1960 ,3039],[1961,3080],[1962,3136],[1963,3206],[1964,3277],[1965,3346],[19 66,3416],[1967,3486],[1968,3558],[1969,3632],[1970,3708],[1971,3785],[ 1972,3862],[1973,3939],[1974,4014],[1975,4088],[1976,4160],[1977,4233] ,[1978,4305],[1979,4381],[1980,4457],[1981,4533],[1982,4613],[1983,469 4],[1984,4774],[1985,4855],[1986,4938],[1987,5023],[1988,5110],[1989,5 196],[1990,5284],[1991,5367],[1992,5450],[1993,5531],[1994,5611],[1995 ,5691],[1996,5769],[1997,5847],[1998,5925],[1999,6003],[2000,6080],[20 01,6157],[2002,6234] ] :" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }} {PARA 0 "" 0 "" {TEXT -1 51 "For the logistic model of population grow th we have" }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 12 "q=a*p-b*p^2;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 1 " " }}{PARA 0 "" 0 "" {TEXT -1 6 "where " }}{PARA 0 "" 0 "" {TEXT -1 0 "" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "q(t)=diff(p(t),t);" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 0 "" }}{PARA 0 "" 0 "" {TEXT -1 71 "Use the data above to estimate q and then do a least squares fit of " }{XPPEDIT 18 0 "q = a*p-b*p^2;" "6#/%\"qG,&*&%\"aG\"\"\"%\"pGF(F(* &%\"bGF()F)\"\"#F(!\"\"" }{TEXT -1 109 " to estimate a and b. Fina lly estimate the limiting population of the Earth ( a/b in the logisti c model)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}{MARK "3" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }