E19 numerical methods for engineering applications spring


E19: Numerical Methods for Engineering Applications Spring 2016 - PROJECT 1

Project: Estimating π-

OVERVIEW

In this project, you will strengthen your programming skills and investigate issues of accuracy and iterative refinement by implementing several simple numerical methods to estimate the constant π.

TASKS

Integration via Riemann Sums. Implement a function intpi(n) that estimates π by computing the integral

π = 401√(1-x2) dx

The integral should be approximated using the following formula:

01f(x) dx ≈ Δx i=0n-1f(xi)

where ?x = 1/n and xi = ?x · i.

Report the output of your function for n = 128, 256, 512, 1024, 2048, and 4096. Also report the true relative error (relative to the constant numpy.pi), as well as approximate relative error given the current estimate and previous estimate (for each value of n after the first one).

Taylor Series. The Maclaurin series (that is, the Taylor series expansion about zero) of the inverse tangent function is given by

Arctan(x) = x - x3/3 + x5/5 - x7/7 + x9/9 · · ·

Using the fact that

π = 4 arctan(1)

implement a function tspi1(n) that estimates π using the first n terms of the Maclaurin series above. Output the estimates for n = 1 through 20. For each estimate, have your program output the approximate relative error given the current and previous estimates, and the true relative error given the actual value of π.

It turns out that a superior method (discovered in 1706 by John Machin1) instead computes

π = 16 arctan (1/5) - 4 arctan (1/239)

Implement another function tspi2(n) that estimates π using the first n terms of the Maclaurin series given the Machin formula. Again, record your program's output for n = 1 through 20 with approximate and true relative errors.

WHAT TO TURN IN

You should submit a zip file containing all of your programs' source code, and a short PDF writeup containing the output of your program and which addresses these points:

  • Describe your approach to implementing each algorithm (about 1-2 paragraphs each).
  • Plot the true error versus the step size ?x for the Riemann sum implementation. Please use a log-log plot.
  • Comment on why the Machin formula is more accurate than the initial formula which computes arctan(1), in terms of Taylor series and truncation error.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: E19 numerical methods for engineering applications spring
Reference No:- TGS01475596

Expected delivery within 24 Hours