The Story So Far

You have made some progress towards generating the examples to "prove" the naysayers wrong (to the standards required in some non-mathematical fields). There are only a few more things to do before you have a fully working solution!

You must create a function which, for a given interval and number of subdivisions, computes the area of the trapezoid.

Specification

Implement the function given by the following docstring:

Use a list comprehension to get a list of the x values of the points, and to pass the values through your function from yesterday.

Use a loop - or read up on the sum function - in order to perform the summation.

"""
Computes, for the function $x^3-3x^2+2x+1$, the trapezoid rule sum.

Parameters
----------
n : int
  The number of trapezoids to use.
a : float, optional
  The start of the interval. Default is 0.
b : float, optional
  The end of the interval.
  Default is 2.

Raises
------
TypeError
  If the first parameter is not an integer
ValueError
  If the interval [a,b] is invalid, or if n is not positive.

Returns
-------
s : float
  The Trapezoid Rule Sum of the function.

Examples
--------
>>> example_trapezoid_sum(1)
2.0

>>> example_trapezoid_sum(4)
2.0
"""

Write and design another function - complete with numpy-style docstring - which returns a list of the sums for a given interval, for all positive subdivision counts $n$ up to a given bound $k$ - with the largest being the trapezoid rule with $k$ trapezoids - controllable by a parameter $k$. Default to the same interval as in the provided docstring.

Assignment: Submit a .py file containing all 3 functions - the two new functions and the one you constructed yesterday - to Brightspace. Remove or comment out anything except the function definitions.

Department of Mathematics, Purdue University
150 N. University Street, West Lafayette, IN 47907-2067
Phone: (765) 494-1901 - FAX: (765) 494-0548
Contact the Webmaster for technical and content concerns about this webpage.
Copyright© 2018, Purdue University, all rights reserved.
West Lafayette, IN 47907 USA, 765-494-4600
An equal access/equal opportunity university
Accessibility issues? Contact the Web Editor (webeditor@math.purdue.edu).