# 33 with which we replace the first row of 1 27 to

• 236

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 33 - 36 out of 236 pages.

33with which we replace the first row of (1.27) to obtain(1.29)-34-11-211-21.........1-211-2u0u1u2...un-2un-1=0-h2g(x1)-h2g(x2)...-h2g(xn-2)-h2g(xn-1).Is thisO(h2)accurate approach at the boundary worth the (ratherminimal) extra effort? Let us investigate with an example. Set theright-hand side of the differential equation tog(x) =cos(πx/2),which corresponds to the exact solutionu(x) =4π2cos(πx/2).Verify thatusatisfies the boundaryconditionsu0(0) =0 andu(1) =0.Figure1.10compares the solutions obtained by solving (1.27) and (1.29)withn=4. Clearly, the simple adjustment that gave theO(h2)ap-proximation tou0(0) =0 makes quite a difference! This figures showsIndeed, we used this small valueofnbecause it is difficult to see thedifference between the exact solutionand the approximation from (1.29) forlargern.that the solutions from (1.27) and (1.29) differ, but plots like this arenot the best way to understand how the approximations compare asn. Instead, compute maximum error at the interpolation points,max0jn|u(xj)-uj|00.10.20.30.40.50.60.70.80.9100.050.10.150.20.250.30.350.40.45xu(x)-3u0+4u1-u2=0u1-u0=0Figure1.10:Approximate solutionsto-u00(x) =cos(πx/2)withu0(0) =u(1) =0. The black curve showsu(x).The red approximation is obtained bysolving (1.27), which uses theO(h)approximationu0(0) =0; the blueapproximation is from (1.29) with theO(h2)approximation ofu0(0) =0. Bothapproximations usen=4.
3410010110210310410-1010-810-610-410-2100nmax0jn|u(xj)-uj|O(h)u1-u0=0O(h2)-3u0+4u1-u2=0Figure1.11:Convergence of approxi-mate solutions to-u00(x) =cos(πx/2)withu0(0) =u(1) =0. The red lineshows the approximation from (1.27);it converges likeO(h)ash0. Theblue line shows the approximationfrom (1.29), which converges likeO(h2).for various values ofn. Figure1.11shows the results of such exper-iments forn=22, 23, . . . , 212. Notice that this figure is a ‘log-log’plot; on such a scale, the errors fall on straight lines, and from theslope of these lines one can determine the order of convergence. Theslope of the red curve is-1, so the accuracy of the approximationsfrom (1.27) isO(n-1) =O(h)accurate. The slope of the blue curve is-2, so (1.29) gives anO(n-2) =O(h2)accurate approximation.How large wouldnneed to be, toget the same accuracy from theO(h)approximation that was producedby theO(h2)approximation withn=212=4096? Extrapolation ofthe red curve suggests we would needroughlyn=108.This example illustrates a general lesson: when constructing finitedifference approximations to differential equations, one must ensurethat the approximations to the boundary conditions have the sameorder of accuracy as the approximation of the differential equationitself. These formulas can be nicely constructed by from derivativesof polynomial interpolants of appropriate degree.
35lecture 6:Interpolating Derivatives

Course Hero member to access this document

Course Hero member to access this document

End of preview. Want to read all 236 pages?

Course Hero member to access this document

Term
Winter
Professor
professor_unknown
Tags
Interpolants