Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(a) Write a MATLAB function called Area1 having two inputs, r and N, and an outp

ID: 2291167 • Letter: #

Question

(a) Write a MATLAB function called Area1 having two inputs, r and N, and an output, A1. The output A1 should be the area under a curve, f(x), for x starting at x start and ending at x end. The input r should be a vector (array) having x_start and x_end as its two elements. The input N should be an integer equal to the number of equal- length sub-intervals in which the interval from x start to x end should be divided. Here, we will use function: fx-0.1x2 + cos(0.4 ? x) +exp(-x2/10) for x-start = 0 and x-end 10. In other words, the Area1.m file which includes the function should look as follows: function A1 Areal(r, N) Code needed to calculate the area... end To compute the approximate area, implement the midpoint approximation method in MATLAB. In other words, the area will be approximately equal to the sum of the rectangular areas (b) Repeat part (a), but call the function Area2, and the corresponding MATLAB file 'Area2.m', and instead of using the midpoint approximation method, use the trapezoid method. (c) Create another script (e.g., main.m) and call A1 Areal(r, N); and A2 Area2(r, N); within a for loop which increases N from 5 to 50 with step of 1. Save the 46 results into vectors A all1 and A_ all2. Then plot A all1 and A all2 with respect to the 46 corresponding values of N in a single plot, and observe how they converge to the true area as N increases. Add appropriate xlabel and ylabel. Which method converges faster? ylabel. Which

Explanation / Answer

input code

function A = Area1(x, N)

x_start = x(1);

x_end = x(2);

i = (x_end - x_start) / N;

x_start = x_start + (i / 2);

= x_end - (i / 2);

x_points = x_start:i:x_end;

A = area = sum((0.1 .* (x_points.^2)) .+ cos(0.4 .* pi .* x_points));

end

A = Area1([0 10], 6);

fprintf("Area under the curve is %.5f ", A)

ourtput

19.86111