Homework 5 - Solutions

Similar documents
Math 104A - Homework 3

Exact and Approximate Numbers:

Cubic Splines MATH 375. J. Robert Buchanan. Fall Department of Mathematics. J. Robert Buchanan Cubic Splines

3.1: 1, 3, 5, 9, 10, 12, 14, 18

Department of Applied Mathematics and Theoretical Physics. AMA 204 Numerical analysis. Exam Winter 2004

Numerical Integration (Quadrature) Another application for our interpolation tools!

Numerical integration and differentiation. Unit IV. Numerical Integration and Differentiation. Plan of attack. Numerical integration.

Mathematical Methods for Numerical Analysis and Optimization

CS 450 Numerical Analysis. Chapter 8: Numerical Integration and Differentiation

Jim Lambers MAT 460/560 Fall Semester Practice Final Exam

Wed Jan Improved Euler and Runge Kutta. Announcements: Warm-up Exercise:

COURSE Numerical integration of functions (continuation) 3.3. The Romberg s iterative generation method

Advanced Higher Grade

MA 114 Worksheet #01: Integration by parts

8.4 Integration of Rational Functions by Partial Fractions Lets use the following example as motivation: Ex: Consider I = x+5

Introductory Numerical Analysis

Answers to Homework 9: Numerical Integration

The Fundamental Theorem of Calculus Part 3

Chapter 6. Legendre and Bessel Functions

Numerical Analysis & Computer Programming

Lecture 1 INF-MAT3350/ : Some Tridiagonal Matrix Problems

Chapter 6. Nonlinear Equations. 6.1 The Problem of Nonlinear Root-finding. 6.2 Rate of Convergence

MATHEMATICAL METHODS INTERPOLATION

n 1 f n 1 c 1 n+1 = c 1 n $ c 1 n 1. After taking logs, this becomes

you expect to encounter difficulties when trying to solve A x = b? 4. A composite quadrature rule has error associated with it in the following form

INTERPOLATION Background Polynomial Approximation Problem:

2D1240 Numerical Methods II / André Jaun, NADA, KTH NADA

TABLE OF CONTENTS INTRODUCTION, APPROXIMATION & ERRORS 1. Chapter Introduction to numerical methods 1 Multiple-choice test 7 Problem set 9

MATH 3511 Lecture 1. Solving Linear Systems 1

(f(x) P 3 (x)) dx. (a) The Lagrange formula for the error is given by

Math Review. Daniel B. Rowe, Ph.D. Professor Department of Mathematics, Statistics, and Computer Science. Copyright 2018 by D.B.

Numerical Methods I: Numerical Integration/Quadrature

(a) Show that there is a root α of f (x) = 0 in the interval [1.2, 1.3]. (2)

Lecture 8: Calculus and Differential Equations

Lecture 8: Calculus and Differential Equations

Homework and Computer Problems for Math*2130 (W17).

Initial value problems for ordinary differential equations

Unit 3. Integration. 3A. Differentials, indefinite integration. y x. c) Method 1 (slow way) Substitute: u = 8 + 9x, du = 9dx.

Homework set #7 solutions, Math 128A J. Xia

Chapter 5 HIGH ACCURACY CUBIC SPLINE APPROXIMATION FOR TWO DIMENSIONAL QUASI-LINEAR ELLIPTIC BOUNDARY VALUE PROBLEMS

Integration, differentiation, and root finding. Phys 420/580 Lecture 7

Daily Lessons and Assessments for AP* Calculus AB, A Complete Course Page 584 Mark Sparks 2012

Monte Carlo Integration I

Math 75B Practice Problems for Midterm II Solutions Ch. 16, 17, 12 (E), , 2.8 (S)

3.1 Interpolation and the Lagrange Polynomial

2016 FAMAT Convention Mu Integration 1 = 80 0 = 80. dx 1 + x 2 = arctan x] k2

Research Computing with Python, Lecture 7, Numerical Integration and Solving Ordinary Differential Equations

AP Calculus BC : The Fundamental Theorem of Calculus

CS 257: Numerical Methods

Thomas Algorithm for Tridiagonal Matrix

Math Methods 12. Portfolio Assignment 4 Type II. 1. The general formula for the binomial expansion of ( x + y) n is given by 2! 3!

Numerical Methods. King Saud University

Multiple Integrals. Chapter 4. Section 7. Department of Mathematics, Kookmin Univerisity. Numerical Methods.

Numerical Methods with MATLAB

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit V Solution of

Lecture 4.2 Finite Difference Approximation

PARTIAL DIFFERENTIAL EQUATIONS

APPM 1360 Final Exam Spring 2016

Chapter 3: Root Finding. September 26, 2005

Lecture Note 3: Interpolation and Polynomial Approximation. Xiaoqun Zhang Shanghai Jiao Tong University

Applied Numerical Analysis Quiz #2

Example - Newton-Raphson Method

MA 3021: Numerical Analysis I Numerical Differentiation and Integration

Numerical Methods. Root Finding

Engg. Math. II (Unit-IV) Numerical Analysis

April 15 Math 2335 sec 001 Spring 2014

Statistical Geometry Processing Winter Semester 2011/2012

3.3.1 Linear functions yet again and dot product In 2D, a homogenous linear scalar function takes the general form:

Name of the Student: Unit I (Solution of Equations and Eigenvalue Problems)

Numerical Methods for Initial Value Problems; Harmonic Oscillators

Math 56 Homework 1 Michael Downs. ne n 10 + ne n (1)

APPM/MATH Problem Set 6 Solutions

MAE 107 Homework 7 Solutions

CLASS NOTES Computational Methods for Engineering Applications I Spring 2015

Math 2250 Final Exam Practice Problem Solutions. f(x) = ln x x. 1 x. lim. lim. x x = lim. = lim 2

Practice Exam 2 (Solutions)

Given the vectors u, v, w and real numbers α, β, γ. Calculate vector a, which is equal to the linear combination α u + β v + γ w.

Rectilinear Motion. Velocity

Chapter 8 Gauss Elimination. Gab-Byung Chae

Math 19, Homework-1 Solutions

Extrapolation Methods for Approximating Arc Length and Surface Area

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

Lectures 9-10: Polynomial and piecewise polynomial interpolation

COSC 3361 Numerical Analysis I Ordinary Differential Equations (II) - Multistep methods

Math 552 Scientific Computing II Spring SOLUTIONS: Homework Set 1

MATH 552 Spectral Methods Spring Homework Set 5 - SOLUTIONS

(x x 0 )(x x 1 )... (x x n ) (x x 0 ) + y 0.

The stationary points will be the solutions of quadratic equation x

Ordinary differential equation II

The answer in each case is the error in evaluating the taylor series for ln(1 x) for x = which is 6.9.

ERRATA MATHEMATICS FOR THE INTERNATIONAL STUDENT MATHEMATICS HL (CORE) (2nd edition)

Quaternion Cubic Spline

APPLICATIONS OF FD APPROXIMATIONS FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS

Numerical Methods - Initial Value Problems for ODEs

Solutions Preliminary Examination in Numerical Analysis January, 2017

AP Calculus AB/BC ilearnmath.net

CHAPTER 10 Shape Preserving Properties of B-splines

MATH MIDTERM 4 - SOME REVIEW PROBLEMS WITH SOLUTIONS Calculus, Fall 2017 Professor: Jared Speck. Problem 1. Approximate the integral

MATHEMATICS 9740/01 Paper 1 14 September 2012

Computer Problems for Taylor Series and Series Convergence

Transcription:

Spring Math 54 Homework 5 - Solutions BF 3.4.4. d. The spline interpolation routine below produces the following coefficients: i a i b i c i d i -..869948.75637848.656598 -.5.9589.487644.9847639.887.9863.34456976.489747 -.9393648 which gives the natural cubic spline: S () =.869948 +.75637848( + ) +.656598( + ) 3, [,.5], S () =.9589 +.487644( +.5) +.9847639( +.5) +.887( +.5) 3, [.5, ], S () =.9863 +.34456976 +.489747.9393648 3, [,.5]..3.5..5..5.95.9.85.5.5 Main Code function z = spline(n,, f) clear all load e344d n =length(f); for i = :n- h(i) = (i+)-(i); a = f; for i = :n-

alpha(i-) = (3./h(i)).*(a(i+)-a(i))-(3./h(i-)).*(a(i)-a(i-)); rhs = [ alpha ] ; for i = :n- l(i) = *(h(i)+h(i+)); T = [ h(:n-) ; l(:n-) ; h(:n-) ] ; c = trisolve(t, rhs); for j = :n- b(j) = (a(j+)-a(j))./h(j)-h(j)*(c(j+)+*c(j))./3; d(j) = (c(j+)-c(j))./(3*h(j)); y = min():.:ma(); Sy = evalspline(a,b,c,d,,y); plot(y, Sy, -,, f, o ) print -depsc spline_free.eps Evaluation Subroutine function S = evalspline(a,b,c,d,,y) Inputs: a-b-c-d the coefficients that define the spline are the node-points y the point(s) where you want to evaluate the spline function S = evalspline(a,b,c,d,,y) if( length(a) ~= length() ) error([ The first argument (a) must be the same length as the 5th... argument () ]); if( length(b) < length()- ) error([ The second argument (b) cannot be more then one element... shorter than the 5th argument () ]); if( length(c) ~= length() ) error([ The third argument (a) must be the same length as the 5th... argument () ]); if( length(d) < length()- )

error([ The second argument (b) cannot be more then one element... shorter than the 5th argument () ]); if( min(y) < min() ) error([ The values in the 6th argument (y) should not be less than... the values in the 5th argument () ]); if( ma(y) > ma() ) error([ The values in the 6th argument (y) should not be greather... than the values in the 5th argument () ]); S = zeros(size(y)); for k = :length(y) n = min([length(b) ma(find(<=y(k)))]); S(k) = polyval([d(n) c(n) b(n) a(n)],(y(k)-(n))); Tridiagonal solver Solver for tri-diagonal matrices. T must be in compact form: the sub-diagonal elements in the first column, the diagonal in the second column, and the super-diagonal in the third column. Note that T(,) and T(3,n) are never accessed, i.e. the subdiagonal entries start on the second row, and the superdiagonal elements on the (n-)st row. function []=trisolve(t,b) if nargin ~= error( trisolve:: two input arguments required. ) if nargout ~= error( trisolve: one output argument required. ) [n,m] = size(t); if m ~= 3 error( trisolve: matri must have three columns. )

[N,M] = size(b); if N ~= n error( trisolve: rhs and matri must have same number of rows. ); work = zeros(n,); work() = T(,); (,:) = b(,:); Forward sweep. for i=:n beta = T(i,)/work(i-); (i,:) = b(i,:) - beta*(i-,:); work(i) = T(i,) - beta*t(i-,3); (n,:) = (n,:)/work(n); Backward sweep. for i=n-:-: (i,:) = ((i,:) - T(i,3)*(i+,:)) / work(i); BF 3.4.6. d. The data for the above problem were generated from the function f() = ln(e + ). We evaluate the f() and S () at =.5 and find the absolute error giving: S (.5) =.99454 f(.5) =.896993 S (.5) f(.5) =.353. Similarly, we evaluate the derivative of the spline and the function to obtain: S (.5) =.39739958 f (.5) =.399935 S (.5) f (.5) =.6488. BF 3.4.8. d. The clamped spline interpolation routine below produces the following coefficients: i a i b i c i d i -..869948.55364.653747467.6367 -.5.9589.3739567.893795867.54.9863.33338433.999467.87579733 which gives the clamped cubic spline:

S () =.869948 +.55364( + ) +.653747467( + ) +.6367( + ) 3, [,.5], S () =.9589 +.3739567( +.5) +.893795867( +.5) +.54( +.5) 3, [.5, ], S () =.9863 +.33338433 +.999467 +.87579733 3, [,.5]..3.5..5..5.95.9.85.5.5 Main Code function z = spline_clp(n,, f) clear all load e344d fp =.55364; fpn =.458676; n =length(f); for i = :n- h(i) = (i+)-(i); a = f; alpha = 3*(a()-a())/h()-3*fp; alphan = 3*fpn -3*(a(n)-a(n-))/h(n-); for i = :n- alpha(i-) = (3./h(i)).*(a(i+)-a(i))-(3./h(i-)).*(a(i)-a(i-)); rhs = [alpha alpha alphan] ; t = *h();

tnn = *h(n-); for i = :n- l(i) = *(h(i)+h(i+)); T = [ h(:n-) ; t l(:n-) tnn ; h(:n-) ] ; c = trisolve(t, rhs); for j = :n- b(j) = (a(j+)-a(j))./h(j)-h(j)*(c(j+)+*c(j))./3; d(j) = (c(j+)-c(j))./(3*h(j)); y = min():.:ma(); Sy = evalspline(a,b,c,d,,y); plot(y, Sy, -,, f, o ) print -depsc spline_clpd.eps BF 4..5. The three-point formulae for derivatives are f ( ) = h [ 3f( ) + 4f( + h) f( + h)] + h 3 f (3) (ξ ), f ( ) = h [ f( h) + f( + h)] + h 6 f (3) (ξ ), f ( ) = h [f( h) 4f( h) + 3f( + h)] + h 3 f (3) (ξ ), f() f () 8. 6.944 3.95 8.3 7.5649 3.65 8.5 8.956 3.39975 8.7 8.89 3.6355 BF 4.4.(a). For trapezoid rule, we see that with n = 4.5.5 BF 4.4.(c). We see that with n = 8.75.75 cos ()d.993343. (sin ()) sin() + )d.48937. The trapezoid rule is given by the MatLab program: Trapezoid Method for BF 4.4; f = inline( (cos())^ ); n = 4;

a = -.5; b =.5; h = (b-a)/n; fprintf( ------------------------------------------------\n ); fprintf( n h sum \n ); fprintf( ------------------------------------------------\n ); sum = h*(f(a)+f(b))/; for j = :(n-) = a+j*h; sum = sum + h*f(); fprintf( 3d 8.6e.8f \n,n, h, sum); BF 4.4.4(a). For Simpson s rule, we see that with n = 4.5 cos ()d.98865..5 BF 4.4.4(c). We see that with n = 8.75 (sin ()) sin() + )d.4898..75 The Simpson s rule is given by the MatLab program: Simpson Method; f = inline( (cos())^ ); n = 4; a = -.5; b =.5; h = (b-a)/n; k = n/; fprintf( ------------------------------------------------\n ); fprintf( n h sum \n ); fprintf( ------------------------------------------------\n ); sum = h*(f(a)+f(b))/3; = a+h; sum = sum + (4*h/3)*f(); for j = :(k-) = a+(*j)*h; = a+(*j+)*h; sum = sum + (*h/3)*f()+(4*h/3)*f(); fprintf( 3d 8.6e.8f \n,n, h, sum);

BF 4.4.. We integrate and obtain π cos()d = π = 6.838538. The codes above to increase n until the accuracy is within tolerance ( 4 ). a. The Composite Trapezoid Rule requires n = 8 with h =.3779 to obtain the approimation: π cos()d 6.83847. b. The Composite Simpson s Rule requires n = 8 with h =.74533 to obtain the approimation: π cos()d 6.838755. c. The Composite Midpoint Rule requires n = 3 with h =.97565 to obtain the approimation: π cos()d 6.83856. BF 4.6.6(a). We want to compute. ( sin d =.4558834, ) where Maple gives us the value above. We use the Adaptive Quadrature with the Composite Simpson s rule. The tolerance is set at 3 for the program (given in class). The graphs below show the function and the refinement levels to obtain the solution to the level of desired accuracy. The computed value of the integral is.454998, with an error of.68 4. Adaptive CSR The Function 8 Adaptive CSR Refinement Levels.8 7 f().6.4...4.6 Refinement Level 6 5 4 3.8.5.5.5.5 BF 4.7.(b). We use Maple to show that e d = 5e =.66794.

To use Gaussian quadrature, we first convert the integral to be defined on t [, ], so we have e d = ( ) t + t+ e ( ) dt. Using Gaussian quadrature with n =, we have e d [ (r ) + e ( r ) ( ) + r + + e ( r ) ] + =.594439, where r =.5773569 = r. The absolute error is.94. BF 4.7.(g). We use Maple to show that 3.5 3 4 d = 4 3.5 3 =.63633458. To use Gaussian quadrature, we first convert the integral to be defined on t [, ], so we have 3.5 3 4 d = (t + 3)/4 4 (t + 3) /6 4 dt. Using Gaussian quadrature with n =, we have 3.5 3 4 d [ ] (r + 3)/4 4 (r + 3) /6 4 + (r + 3)/4 (r + 3) /6 4 where r =.5773569 = r. The absolute error is.678. =.63696565, BF 4.7.(b). We use the conversions above to get the form for the Gaussian quadrature. Using Gaussian quadrature with n = 3, we have e d [ ( ) r + c e ( r ) ( ) + + c e ( ( ) r + ) + c e ( r ) ] + =.65953868, where r =.774596669 = r and c =.5555555556 and c =.8888888889. The absolute error is.7473. BF 4.7.(g). We use the conversions above to get the form for the Gaussian quadrature. Using Gaussian quadrature with n = 3, we have 3.5 3 4 d [ ] c (r + 3)/4 4 (r + 3) /6 4 + c 3/4 (3) /6 4 + c (r + 3)/4 (r + 3) /6 4 =.636396, where r =.774596669 = r and c =.5555555556 and c =.8888888889. The absolute error is.499 7.

BF 4.8.(a). We use Maple to solve.5.4.. y dyd =.5. y 3 3.4 =.35733334.. Net we approimate the double integral with Simpson s rule using m = n = 4. The program below produces.5.4.. y dyd.357333. We note that there is no error between the actual value of the double integral and the Simpson rule approimation, which should be true as Simpson s rule solves polynomials degree less than or equal to 3. (The integrand is linear in and quadratic in y, so the values will be eact in each direction.) f = inline( *y^ ); c = inline(. ); d = inline(.4 ); a =.; b =.5; m = 4; n = 4; h = (b-a)/n; An = ; Ae = ; Ao = ; for i = :n = a + i*h; ya = c(); yb = d(); hy = (d() - c())/m; Bn = f(,ya) + f(,yb); Be = ; Bo = ; for j = :m- y = ya + j*hy; z = f(,y); if rem(j,)== Be = Be + z; else Bo = Bo + z; A = (Bn + 4*Bo + *Be)*hy/3; if i == i == n An = An + A; else if rem(i,)== Ae = Ae + A;

else Ao = Ao + A; Dint = (An + 4*Ao + *Ae)*h/3; fprintf(, \n Double Integral is.8f \n,dint); BF 4.8.(c). We use Maple to solve. ( ). ( + y 3 y )dyd = + y4 4 =. ( 3 + 5 ) 4 4 d = 6.5864. Net we approimate the double integral with Simpson s rule using m = n = 4. The program below produces. ( + y 3 )dy d 6.586463. Again we note that there is almost no error between the actual value of the double integral and the Simpson rule approimation. BF 4.8.(a). The notes above about Simpson s rule solving eactly any polynomial of degree less than or equal to 3 means that we can use n = m =, the smallest possible values of n and m to get the actual value of the integral, which requires 9 function evaluations. BF 4.8.(c). The notes above about Simpson s rule solving eactly any polynomial of degree less than or equal to 3 means that we can use m =, the smallest possible values of m to get the actual value of the integral in the y direction. With n =, the approimation is not quite sufficiently accurate (in the direction it is a polynomial of order 4), but increasing to n = 4 gives the approimate double integral accurate to 6 of the actual value. Thus, if we require m = n, then m = n = 4, which requires 5 function evaluations. BF 4.9.(a). u =, so This integral has a singularity at =, so we transform the integral with which is singular at u =. With e e u d = du = [ P 4 (u) ] du + G(u)du, u e u P 4 (u) = + u + u + u3 6 + u4 4 The integral with P 4 (u) is easily handled, giving and G(u) = P 4 (u) u du =.93544974. { e u P 4 (u) u, u,, u =, We apply Simpson s rule with n = 6 to the integral for G(u), so G(u)du (G() + 4G(/6) + G(/3) + 4G(/) + G(/3) + 4G(5/6) + G()) 8 =.7666.

e d = [ P 4 (u) ] du + G(u)du (.93544974+.7666) =.7659786. e u e BF 4.9.3(c). With the transformation of = t, we have cos() cos(/t) 3 d = t 3 ( t )dt = t cos(/t)dt. Clearly, lim t t cos(/t) =, so we directly apply the Composite Simpson s rule with n = 6. With G(t) = t cos(/t), the result is t cos(/t)dt = (G() + 4G(/6) + G(/3) + 4G(/) + G(/3) + 4G(5/6) + G()) 8.556869. The actual value is.876, so there a significant error in this calculation as one might epect from the rapid oscillations of the cosine function near t =. Problem. A number of these integrals have singularities, so it is useful to use a quadrature technique that does not evaluate at the points. Gaussian quadrature has the approimately the same accuracy as the Simpson s method. Below is a Composite Gaussian quadrature program that does successive halving of the interval size until the tolerance is met. f = inline( sin()/ ); a = ; b = *pi; tol = ^(-6); ma_iter = ; n = ; fprintf( ------------------------------------------------\n ); fprintf( n h sum \n ); fprintf( ------------------------------------------------\n ); h = b-a; u = a + h*(-/sqrt(3))/; v = a + h*(+/sqrt(3))/; sum = h*(f(u)+f(v))/; sum = sum; fprintf( 3d 8.6e.8f \n,n, h, sum); while(n < ma_iter) m = ^n; sum = ; h = (b-a)/m; for j = :m u = a + (j-)*h + h*(-/sqrt(3))/; v = a + (j-)*h + h*(+/sqrt(3))/; sum = sum + h*(f(u)+f(v))/; diff = abs(sum - sum);

fprintf( 3d 8.6e.8f \n,m, h, sum); if (diff < tol) return; sum = sum; n = n+; Part A. We split the integral into two parts and transform the second integral with t =, so e t4 dt = = e t4 dt + e t4 dt + e t4 dt e 4 d Each of these integrals are solved using the algorithm above. We obtain e 4 e t4 dt + d.84483859 +.656386 =.96445. We iterated these integrals until the tolerance was 6. The stepsize for the first was h = /3, and the second was h = /6. A graph of the integrand is seem below.

y = e t4 y = sin(t)/t y.8.8.6.6 y.4.4.. 3 4 5 Problem A. 3 4 5 6 Problem B Part B. We used the Gaussian quadrature algorithm above for the integral below and iterated until the tolerance was 6. The final stepsize was h = /3, and the resulting integral is approimated by π sin(t) dt.4856. t A graph of the integrand is seem above. Part C. The integrand for this integral oscillates wildly. We tried both the Gaussian quadrature formula above and the adaptive CSR. The latter should be more efficient computing the integral as the integrand for smaller t is well-behaved. The Gaussian quadrature needed to use a stepsize of h = /496 to be within a tolerance of 5, while the graph below shows the stepsizes for the adaptive CSR for a tolerance of 5 The resulting integral is approimated by 5 sin(t 4 ) dt.34883349 (for ACSR =.34883335). A graph of the integrand is seem below. y = sin(t 4 ) 4 Adaptive CSR Refinement Levels y.5.5 Refinement Level 8 6 4 3 4 5 Problem C 3 4 5 Problem C steps