Question: Implement a python function which can numerically integrate a mathematical function. A simple approach based on the Riemann sum is sufficient. Use it to evaluate
Implement a python function which can numerically integrate a mathematical function. A simple approach based on the Riemann sum is sufficient.
Use it to evaluate the following definite integrals:
pi arccoscosxcosx dx
coshx dx
e xdx
dx
Feel free to use numpy except for functions like nptrapz
Report and test your answers, making sure each is accurate to decimal digits. the exact values are pi ee and
Additionally, the last integral has to be correct given a small number of discretization steps, say, using the same function as the others without handling this extra case in a special way It's essentially meant as a unit test for your algorithm and its implementation. You can use the function provided below.import numpy as np
def constantfunctionofonex:
Evaluates a constant function returning
It handles both a single number and nparray as input.
Args:
x: either a float or nparray of length n
Returns:
either a single as a float or a lengthn nparray of
return x
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
