(*^ ::[ Information = "This is a Mathematica Notebook file. It contains ASCII text, and can be transferred by email, ftp, or other text-file transfer utility. It should be read or edited using a copy of Mathematica or MathReader. If you received this as email, use your mail application or copy/paste to save everything from the line containing (*^ down to the line containing ^*) into a plain text file. On some systems you may have to give the file a name ending with ".ma" to allow Mathematica to recognize it as a Notebook. The line below identifies what version of Mathematica created this file, but it can be opened using any other version as well."; FrontEndVersion = "Macintosh Mathematica Notebook Front End Version 2.2"; MacintoshStandardFontEncoding; fontset = title, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e8, 24, "Times"; fontset = subtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, bold, e6, 18, "Times"; fontset = subsubtitle, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeTitle, center, M7, italic, e6, 14, "Times"; fontset = section, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, grayBox, M22, bold, a20, 18, "Times"; fontset = subsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, blackBox, M19, bold, a15, 14, "Times"; fontset = subsubsection, inactive, noPageBreakBelow, nohscroll, preserveAspect, groupLikeSection, whiteBox, M18, bold, a12, 12, "Times"; fontset = text, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = smalltext, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = input, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeInput, M42, N23, bold, L-2, 12, "Courier"; fontset = output, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-2, 12, "Courier"; fontset = message, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, R32768, L-2, 12, "Courier"; fontset = print, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, L-2, 12, "Courier"; fontset = info, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeOutput, M42, N23, B32768, L-2, 12, "Courier"; fontset = postscript, PostScript, formatAsPostScript, output, inactive, noPageBreakInGroup, nowordwrap, preserveAspect, groupLikeGraphics, M7, l34, w282, h287, 12, "Courier"; fontset = name, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, italic, 10, "Geneva"; fontset = header, inactive, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = leftheader, inactive, L2, 12, "Times"; fontset = footer, inactive, noKeepOnOnePage, preserveAspect, center, M7, 12, "Times"; fontset = leftfooter, inactive, L2, 12, "Times"; fontset = help, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 10, "Times"; fontset = clipboard, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = completions, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special1, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special2, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special3, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special4, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; fontset = special5, inactive, nohscroll, noKeepOnOnePage, preserveAspect, M7, 12, "Times"; paletteColors = 128; currentKernel; ] :[font = title; inactive; preserveAspect; startGroup] Linear Methods of Applied Mathematics Selected solutions for Chapter II ;[s] 3:0,0;38,1;39,0;75,-1; 2:2,25,18,Times,1,24,0,0,0;1,13,9,Times,1,12,0,0,0; :[font = text; inactive; preserveAspect; plain; bold] (c) Copyright 1994-1997 by Evans M. Harrell II and James V. Herod. All rights reserved. :[font = text; inactive; Cclosed; preserveAspect; plain; bold; startGroup] Notes for the instructor. ;[s] 2:0,1;25,0;26,-1; 2:1,13,9,Times,1,12,0,0,0;1,11,8,Times,1,9,0,0,0; :[font = text; inactive; preserveAspect; endGroup] This contains calculations and examples which correlate with chapter 2 of the WWW text by Harrell and Herod. Students can be encouraged to cut and paste from this notebook to do homework. :[font = subsubsection; inactive; Cclosed; preserveAspect; startGroup] Instructions :[font = text; inactive; preserveAspect; endGroup] This notebook uses Mathematica to perform calculations for Harrell and Herod's hypertext book, Linear Methods of Applied Mathematics. The student needs only a basic knowledge of Mathematica to use the notebook, which is designed both to show how to work problems in the text and to provide a template for using Mathematica to work other problems of the student's own design. Calculations will be performed when the reader presses enter in a given calculation cell (bold print). It is best to activate the cells in order, so that Mathematica will be able to call on operators and functions defined in earlier cells. Red color coding is used to warn the reader when a given calculation relies on an earlier one. ;[s] 11:0,0;19,1;30,0;96,1;133,0;181,1;192,0;315,1;326,0;538,1;549,0;721,-1; 2:6,13,9,Times,0,12,0,0,0;5,13,9,Times,2,12,0,0,0; :[font = section; inactive; Cclosed; preserveAspect; startGroup] Exercise II.1 :[font = text; inactive; preserveAspect] II.1. Find the norms of and "angles" between the following functions defined for -1 = ||f|| ||g|| cos(q), where q is the angle requested. We can automate this whole problem by defining commands in Mathematica for operations such as the inner product , etc. Since one of the functions involved is complex-valued, we need to remember that one of the functions in the inner product must be complex conjugated. (Unfortunately, Mathematica is not very clever about manipulating functions which have neen complex conjugated, so it is best to make a special identity to use when needed.) ;[s] 9:0,0;50,1;51,0;60,1;61,0;146,2;157,0;380,2;391,0;538,-1; 3:5,13,9,Times,0,12,0,0,0;2,18,13,Symbol,0,12,0,0,0;2,13,9,Times,2,12,0,0,0; :[font = input; preserveAspect] ConjId = Exp[I Pi x] -> Exp[- I Pi x]; :[font = input; preserveAspect] InnerP[f_,g_, {x_,a_,b_}] := Integrate[f (g /. ConjId), {x, a, b}] ;[s] 3:0,0;47,1;53,0;67,-1; 2:2,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = input; preserveAspect] FunNorm[f_, {x_,a_,b_}] := Sqrt[InnerP[f,f,{x,a,b}]] ;[s] 3:0,0;32,1;38,0;53,-1; 2:2,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = input; preserveAspect] FunCos[f_,g_, {x_,a_,b_}] := InnerP[f,g,{x,a,b}] \ / (FunNorm[f,{x,a,b}] FunNorm[g,{x,a,b}]) ;[s] 7:0,0;29,1;35,0;79,1;86,0;98,1;105,0;118,-1; 2:4,12,10,Courier,1,12,0,0,0;3,12,10,Courier,1,12,65535,0,0; :[font = text; inactive; preserveAspect] We'll calculate some representative cosines and angles from the exercise: :[font = input; preserveAspect; startGroup] FunCos[1,x,{x,-1,1}] ;[s] 2:0,1;6,0;21,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] 0 ;[o] 0 :[font = text; inactive; preserveAspect] I.e., these functions are orthogonal; the angle is Pi/2. :[font = input; preserveAspect; startGroup] FunCos[x^2,Cos[Pi x],{x,-1,1}] ;[s] 2:0,1;6,0;31,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] (-2*10^(1/2))/Pi^2 ;[o] -2 Sqrt[10] ----------- 2 Pi :[font = text; inactive; preserveAspect] To get the angle in radians: :[font = input; preserveAspect; startGroup] ArcCos[%] //N ;[s] 3:0,0;7,1;8,0;14,-1; 2:2,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] 2.266351092824799512 ;[o] 2.26635 :[font = input; preserveAspect; startGroup] FunCos[x,Exp[I Pi x],{x,-1,1}] ;[s] 2:0,1;6,0;31,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] (3^(1/2)*((-1 - I*Pi)/Pi^2 - (-1 + I*Pi)/Pi^2))/2 ;[o] -1 - I Pi -1 + I Pi Sqrt[3] (--------- - ---------) 2 2 Pi Pi ------------------------------- 2 :[font = input; preserveAspect; startGroup] Simplify[%] :[font = output; output; inactive; preserveAspect; endGroup] (-I*3^(1/2))/Pi ;[o] -I Sqrt[3] ---------- Pi :[font = input; preserveAspect; startGroup] FunCos[x^2,Exp[I Pi x],{x,-1,1}] ;[s] 2:0,1;6,0;33,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] (5^(1/2)*((2*I - 2*Pi - I*Pi^2)/Pi^3 - (2*I + 2*Pi - I*Pi^2)/Pi^3))/2 ;[o] 2 2 2 I - 2 Pi - I Pi 2 I + 2 Pi - I Pi Sqrt[5] (------------------ - ------------------) 3 3 Pi Pi ------------------------------------------------- 2 :[font = input; preserveAspect; startGroup] Simplify[%] ;[s] 3:0,0;9,1;10,0;12,-1; 2:2,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup] (-2*5^(1/2))/Pi^2 ;[o] -2 Sqrt[5] ---------- 2 Pi :[font = section; inactive; Cclosed; preserveAspect; startGroup] Exercise II.7 :[font = text; inactive; preserveAspect] In each case below, find a) the multiple of g which is closest in the mean-square sense to f, and b) a function of the form f - a g which is orthogonal to f. If for some reason this is not possible, interpret the situation geometrically. (i) f(x) = sin(pi x), g(x) = x, 0 < x < 1 (ii) f(x) = sin(pi x), g(x) = x, -1 < x < 1 (iii) f(x) = cos(pi x), g(x) = x, -1 < x < 1 (iv) f(x) = x^2 - 1, g(x) = x^2 + 1, -1 < x < 1 ;[s] 3:0,0;133,1;135,0;424,-1; 2:2,13,9,Times,0,12,0,0,0;1,18,13,Symbol,0,12,0,0,0; :[font = subsection; inactive; Cclosed; preserveAspect; startGroup] Solution for part a) :[font = text; inactive; preserveAspect] The closest multiple of g would be the projection of f onto g. We may automate this just as in the notebook ch2.ma: ;[s] 3:0,0;4,1;11,0;117,-1; 2:2,13,9,Times,0,12,0,0,0;1,13,9,Times,1,12,0,0,0; :[font = input; preserveAspect] Projf[f_,g_, {x_,a_,b_}] := g Integrate[(f g /. x -> intvar), {intvar,a,b}] \ / Integrate[(g^2 /. x -> intvar), {intvar,a,b}] :[font = text; inactive; preserveAspect] Thus the answers are: :[font = input; preserveAspect; startGroup] Projf[Sin[Pi x], x, {x,0,1}] ;[s] 2:0,1;5,0;29,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] (3*x)/Pi ;[o] 3 x --- Pi :[font = input; preserveAspect; startGroup] Projf[Sin[Pi x], x, {x,-1,1}] ;[s] 2:0,1;5,0;30,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] (3*x)/Pi ;[o] 3 x --- Pi :[font = input; preserveAspect; startGroup] Projf[Cos[Pi x], x, {x,-1,1}] ;[s] 2:0,1;5,0;30,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] 0 ;[o] 0 :[font = input; preserveAspect; startGroup] Projf[x^2 - 1, x^2 + 1, {x,-1,1}] ;[s] 2:0,1;5,0;34,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup; endGroup] (-3*(1 + x^2))/7 ;[o] 2 -3 (1 + x ) ----------- 7 :[font = subsection; inactive; Cclosed; preserveAspect; startGroup] Solution for part b) :[font = text; inactive; preserveAspect] If f - a g is orthogonal to f, then 0 = = - a , so a = / ;[s] 9:0,0;7,1;9,0;58,1;60,0;76,1;79,0;101,1;105,0;120,-1; 2:5,13,9,Times,0,12,0,0,0;4,18,13,Symbol,0,12,0,0,0; :[font = input; preserveAspect] Alpha[f_,g_, {x_,a_,b_}] := InnerP[f,f,{x,a,b}] \ /InnerP[f,g,{x,a,b}] ;[s] 5:0,0;28,1;34,0;82,1;88,0;102,-1; 2:3,12,10,Courier,1,12,0,0,0;2,12,10,Courier,1,12,65535,0,0; :[font = text; inactive; preserveAspect] Answers: :[font = input; preserveAspect; startGroup] Alpha[Sin[Pi x], x, {x,0,1}] ;[s] 2:0,1;5,0;29,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] Pi/2 ;[o] Pi -- 2 :[font = input; preserveAspect; startGroup] Alpha[Sin[Pi x], x, {x,-1,1}] ;[s] 2:0,1;5,0;30,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup] Pi/2 ;[o] Pi -- 2 :[font = input; preserveAspect; startGroup] Alpha[Cos[Pi x], x, {x,-1,1}] ;[s] 2:0,1;5,0;30,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = message; inactive; preserveAspect] 1 Power::infy: Infinite expression - encountered. 0 :[font = output; output; inactive; preserveAspect; endGroup] DirectedInfinity[] ;[o] ComplexInfinity :[font = text; inactive; preserveAspect] The difficulty in (iii) is that the two functions are orthogonal. :[font = input; preserveAspect; startGroup] Alpha[x^2 - 1, x^2 + 1, {x,-1,1}] ;[s] 2:0,1;5,0;34,-1; 2:1,12,10,Courier,1,12,0,0,0;1,12,10,Courier,1,12,65535,0,0; :[font = output; output; inactive; preserveAspect; endGroup; endGroup; endGroup; endGroup] -2/3 ;[o] 2 -(-) 3 ^*)