Question

Problem 1 The midpoint rule for approximating an integral can be expressed as [flwydcm) x n s(a – žn+ in where h = (b -a)/n.c) Write another vectorized midpoint function midpointnsum(f, a, b, n) using the Numpy sum function.d) Benchmark your functions with the same limits for n = 1000.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
https://trinket.io/python3/9020deab0c

Please note this is the function only as asked in question and in order to run it you have to pass f,a,b and n as arguments in it

import numpy as np
def midpointnsum(f,a,b,n=1000):
h=float(b-a)/float(n)
i=np.arange(1,n+1);
x=a-0.5*h+i*h;
y=h*np.sum(f(x));
return y;

Add a comment
Know the answer?
Add Answer to:
Problem 1 The midpoint rule for approximating an integral can be expressed as ["flwydcm) x n...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT