1)
a) Write a MATLAB function called Area1 having two inputs, r andN, and an output, A1. The output A1 should be the area under acurve, f(x), for x starting at x_start and ending at x_end. Theinput r should be a vector (array) having x_start and x_end as itstwo elements. The input N should be an integer equal to the numberof equallength sub-intervals in which the interval from x_start tox_end should be divided. Here, we will use function: f(x) = 0.1x 2+ cos(0.4 ? x) +exp(-x 2 /10) for x_start = 0 and x_end = 10. Inother words, the Area1.m file which includes the function shouldlook as follows:
function A1 = Area1(r, N)
……. Code needed to calculate the area…..
end
To compute the approximate area, implement the midpointapproximation method in MATLAB. In other words, the area will beapproximately equal to the sum of the rectangular areas.
(b) Repeat part (a), but call the function Area2, and thecorresponding MATLAB file ‘Area2.m’, and instead of using themidpoint approximation method, use the trapezoid method.
(c) Create another script (e.g., main.m) and call A1 = Area1(r,N); and A2 = Area2(r, N); within a for loop which increases N from5 to 50 with step of 1. Save the 46 results into vectors A_all1 andA_all2. Then plot A_all1 and A_all2 with respect to the 46corresponding values of N in a single plot, and observe how theyconverge to the true area as N increases. Add appropriate xlabeland ylabel. Which method converges faster?