E19 numerical methods for engineering applications spring


E19: Numerical Methods for Engineering Applications Spring 2016 - HOMEWORK 2

You will want to download and inspect the assignment.zip archive from the course website before answering these questions. Please submit a zipfile to the course Moodle page which contains a PDF writeup with answers to questions 1 and 2, and source code for question 3.

1. Associativity of addition

The hw2_sum.py program shows that adding two small lists of floating point numbers that differ only in their order may produce two different numerical results.

a. Why does this happen?

b. What does this imply about the associative property of floating point addition?

c. What other algebraic properties are similarly "funny" for floating point numbers? Give examples if you can.

2. Instability of numerical differentiation

Later in the course we will learn more about numerical approximations to the derivative. For now, it is sufficient to say that the derivative of some function f(x) can be well approximated by

f'(x) ≈ f(x+h) - f(x-h)/2h

for some small step size h.

The hw2_diff.py program illustrates this by repeatedly computing the first, second, third, etc. derivatives of sinpxq numerically, and comparing the computed value to the true function values of cos(x), -sin(x), -cos(x), etc.

A funny thing happens in the program - after just a few iterations, the answer seems to "blow up" with huge numerical errors.

a. What makes this happen? Is this a gradual process or a sudden one?

b. Explain why replacing np.float32 with np.float64 delays-but does not eliminate-the blowup.

c. Explain why the same is true for cutting down the step size h by a factor of 4.

3. Root finding

Modify the hw2_rootfinding.py code to perform the following tasks:

a. Complete the implementation of the Secant Method so the tests run correctly to find the roots of the example functions provided.

b. Ditto for Newton's method.

c. Add a test case in the functions list to define some function f(x) for which the Bisection method outperforms Regula Falsi (i.e. uses significantly fewer iterations). Add a comment in your program indicating why Bisection works better for this function.

d. Add a test case for which the Secant Method fails to converge, but Bisection search converges. Again, add a comment in your program indicating why this happens.

Attachment:- Assignment.zip

Request for Solution File

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

Expected delivery within 24 Hours