Answered step by step
Verified Expert Solution
Question
1 Approved Answer
function A m = midpoint ( a , b , n , f ) Deltax = b - a n ; midpoints = zeros (
function midpoint
Deltax ;
midpoints zeros;
heights midpoints Your Task
Clearly, using the Midpoint Method with more than a few rectangles is difficult due to the large number of calculations involved. However, MATLAB can be used
to quickly perform these calculations, even for very large In this problem you will define a MATLAB function, midpoint, that accepts four inputs:
a the left interval endpoint
b the right interval endpoint
the number of rectangles
a handle to a numeric MATLAB function here is an anonymous function
and returns one output:
A the area approximated using the Midpoint method.
The function declaration has already been provided in the solution template. Complete the function definition by following the steps below:
Compute the rectangle width, Deltax, using the inputs and according to the formula above.
Use the linspace function to generate a vector of equally spaced points between a and b midpoints. Hint: your interval of the midpoints should
not start and end at a and b respectively.
Obtain the vector of rectangle heights, heights, by evaluating the input function at midpoints.
Obtain the vevtor of rectangle areas, a reas, by multiplying the rectangle heights by the rectangle width, Deltax.
Sum the vector of rectangle areas using the sum function to obtain the Midpoint Method area estimate, Am
Code has been provided to test your function using the existing code in the Code to Call Your Function Box. As written, it will call midpoint to estimate the
area for on for You are encouraged to call your function for different values of and to check the corresponding outputs for debugging
purposes.
HELP: of Tests passed
My values
f
function handle with value:
@xx
Am
Am for n:
Am for n:
Am for n:
INCORRECT: Does midpoint return the correct areas for the test cases provided? Pretest
Variable Am has an incorrect value.
Your solution did not return the correct output for n
INCORECT: Does midpoint return the correct areas for different function and interval inputs?
Variable Am has an incorrect value.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started