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.