An approximation to the integral of a function f(x) over an interval [a, b] can be found by first approximating f(x) by the straight line that goes through the end points (a, f(a)) and (b, f(b)), and then finding the area under the straight line, which is the area of a trapezoid.
In python, write a function trapezint(f, a, b) that returns this approximation to the integral. The argument f is a Python implementation of the mathematical function f(x). Test your code by integrating cos(x) and sin(x) from 0 to π.
After replacing the function f(x) with a straight line, we will get a trapezium figure which can be sectorized in two parts (one rectangle and another triangle) and area can be calculated as the sum of the area of the rectangle and the area of the triangle. Please find the attached images for the detailed solution to the question along with python program for the integral.
Get Answers For Free
Most questions answered within 1 hours.