E19 numerical methods for engineering applications spring


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

1. Second-order forward difference approximation to the first derivative

Derive the approximation

f'(x) ≈ 1/2h(-3f(x) + 4f(x+h) - f(x+2h))

and show that it has asymptotic error of O(h2).

2. Dual numbers and partial derivatives

Extend the dual.py code we wrote in class to to use dual numbers to automatically evaluate both partial derivatives of the following function f(x, y):

def f(x, y): return -2.0*x * exp(-(x**2 + y**2)/(4.0))

You should evaluate the function and its derivatives at (x, y) = (0.5, 1.5).

Here are two possible strategies:

  • Easier: Call the function f twice, each time with one Dual object as an argument, and one normal floating point number.
  • Harder: Extend the Dual class so that self.eps is a flat numpy array of length two where the infinitessimal parts correspond to the partials in x and y.

In either case, you will need to provide a definition of the exp function which handles dual numbers correctly (see sqrt and cos in dual.py for examples).

Write a test function to show that your program computes the correct derivatives by comparing to the numerical central difference approximations for the first derivative. Submit a printout of your program and its output.

3. Integrating quadratics and cubics with Simpson's rule

It turns out that for some functions, the adaptive Simspson's integrator we looked at in class doesn't need to do too much work.

a. Why does the code always hit the base case (i.e. does not recurse) when the function f(x) being integrated is any quadratic function?

b. Furthermore, why does the code always hit the base case when the function f(x) being integrated is a cubic function?

4. A new twist on 2D integration

I extended the 2D integral function we worked on in class to create simpsons2d_mystery.

a. What is this function good for? What does it provide that simpsons2d does not?

b. Using traditional calculus notation, write down the 2D integral which is assigned to the mystery variable at the bottom of the program (you need not solve the integral analytically, but it might help you figure out what's going on here).

Attachment:- Assignment.rar

Request for Solution File

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

Expected delivery within 24 Hours