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. Write a function trapezint(f, a, b) that returns this approximation to the integral. Test your code by integrating cos(x) and sin(x) from 0 to π.
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. Write a function trapezint(f, a, b) that returns this approximation to the integral. Test your code by integrating cos(x) and sin(x) from 0 to π.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
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.
Write a function trapezint(f, a, b) that returns this approximation to the integral. Test your code by integrating cos(x) and sin(x) from 0 to π.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images