Matlab Code
% Problem Statement - The area under a curve can be estimated by breaking
% the x-axis into increments, evaluating the function at a point inside
% that increment, and approximating the area under the curve in that
% increment as a rectangle.
%% Housekeeping Commands
clc
clear
%% Variables to be used
% Inputs
% Xmin - the minimum limit of the range
% Xmax - the maximum limit of the range
% Outputs
% area - the final approximation of the area under the curve for the given range
%% Inputs
% This generates the scalars, Xmin and Xmax, with random values which will be used to evaluate your code
% Xmin=randi(5)
% Xmax=Xmin+randi([5 10])
% Test Case 1
Xmin = 0;
Xmax = 10;
% Test case output:
% area = 131.3823
%% Start Programming
Extracted text: Problem Statement The area under a curve can be estimaled by breaking the x asis into increments, evakualing the luncian at a point insice that incrament, and approximating the area under the curve in that incrament as a reclangke. The igure below shows this approximalion with an incronent el 1 and the tunclion being evaluabed al he midpaint of he increment. As the increment deoreases, the approsimation of the aren undor the ourve improves as shown when the ineroments are deereased to 0.25 for the same tunetion as shown abeve. Wto the code hat will calculate the area under the curve: Vina)+ 0.5- (wheru x is in radians using decreasing increments until the aren value converges (the difference between the area from two onsecutive runs is less than 0.01%). Use the midpoint approximation method and start with an increment of 1. Decrease the increment by half every iteration.
Extracted text: Start dePine terms inc set to one Slope I- calculate using definte loop fron Fa Slope2 sct to zero initialize a Counter 52=D0 %3D 2 =4 (use indetante / elagel slapeh loop slapel slopeh (diffrence > 0.01%6 divide inc by 2 S=45 52=45 $z=4.27 ol farsl fime Check:f set slopel eqyak to slape? Use a defnide loop fam Fa to find the slope Courtler not zcre recatautte s tope2 increpent the Conter Usang nen inc lend