python数值计算 Homework # 1, Math 104 A 1

Homework # 1, Math 104 A 1

Instructor: Prof. Hector D. Ceniceros

General Instructions: You have to integrate all the problems that require coding and/or numerical computation in a single jupyter notebook. Make sure all your codes have a pream- ble which describes purpose of the code, all the input variables, the expected output, your name, and the date of the last time you modified it. Write your own code, individually. Do not copy codes! The solutions to the problems that do not require coding must be uploaded as a single pdf or as part of the jupyter notebook.

  1. Review and state the following theorems of Calculus:

    (a) The Intermediate Value Theorem, (b) The Mean Value Theorem,

    (c) Rolle’s Theorem,
    (d) The Mean Value Theorem for Integrals,

    (e) The Weighted Mean Value Theorem for Integrals.

  2. Write a computer code to implement the Composite Trapezoidal Rule quadrature

    􏰂1 1􏰃
    Th[f]=h 2f(x0)+f(x1)+…+f(xN−1)+2f(xN) (1)

    to approximate the definite integral I[f] =

􏰄b a

  1. (a)  Testyourcodewithf(x)=1/(1+x)2 in[0,2]bycomputingtheerror|I[f]−Th[f]| for h = 2/20, 2/40, 2/80, and verify that Th has a convergent trend at the expected, quadratic rate.
  2. (b)  Let f(x) = √x in [0,1]. Compute T1/N for N = 16, 32, 64, 128. Do you see a second order convergence to the exact value of the integral? Explain.

1All course materials (class lectures and discussions, handouts, homework assignments, examinations, web materials) and the intellectual content of the course itself are protected by United States Federal Copyright Law, the California Civil Code. The UC Policy 102.23 expressly prohibits students (and all other persons) from recording lectures or discussions and from distributing or selling lectures notes and all other course materials without the prior written permission of the instructor.

f(x)dx, (2) using the equally spaced points x0 = a,x1 = x0 + h,x2 = x0 + 2h,…,xN = b, where

h = (b − a)/N.

1

3. Consider the definite integral

I[cos x2] =
We cannot calculate its exact value but we can compute accurate approximations to

it using Th[cos x2]. Let

q(h) = Th/2[cos x2] − Th[cos x2] . (4) Th/4[cos x2] − Th/2[cos x2]

  1. (a)  Using your code, find a value of h for which q(h) is approximately equal to 4.
  2. (b)  Get an approximation of the error, I[cos x2] − Th[cos x2], for that particular value

    of h.

  3. (c)  Use this error approximation to obtain the extrapolated, improved, approximation

    Sh[cos x2] = Th[cos x2] + 4 􏰀Th/2[cos x2] − Th[cos x2]􏰁 . (5) 3

  4. (d)  Explain why Sh[cosx2] is more accurate and converges faster to I[cosx2] than Th[cos x2].

􏰄

cos x2dx. (3)

π/2 0

2