Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

function A m = midpoint ( a , b , n , f ) Deltax = b - a n ; midpoints = zeros (

function Am= midpoint (a,b,n,f)
Deltax =b-an;
midpoints =zeros(1,n);
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 n. In this problem you will define a MATLAB function, midpoint, that accepts four inputs:
a, the left interval endpoint
b, the right interval endpoint
n, the number of rectangles
f, a handle to a numeric MATLAB function--f 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 a,b, and n according to the formula above.
Use the linspace function to generate a vector of n 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 f(x)=x2 on 0,1 for n=10. You are encouraged to call your function for different values of n and to check the corresponding out1puts for debugging
purposes.
HELP: 1 of 3 Tests passed
My values
f =
function handle with value:
@(x)x.^2
Am1=
0.3325
Am for n=10: 0.332500
Am for n=100: 0.333325
Am for n=1000: 0.333333
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 =10
INCORECT: Does midpoint return the correct areas for different function and interval inputs?
Variable Am has an incorrect value.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

3rd Edition

0071107010, 978-0071107013

More Books

Students also viewed these Databases questions

Question

Analyse the process of new product of development.

Answered: 1 week ago

Question

Define Trade Mark.

Answered: 1 week ago