# Find the area under a certain section of a plot

6 views (last 30 days)
Andrew Powell on 8 Jan 2020
Answered: Samatha Aleti on 31 Jan 2020
I have a set of data that I have used to plot the graph below. I am needing to find the area of the shaded area but cannot work out how to as I do not know what range of values make up this section and, as the data loops round multiple times there will be a few sets. The data used was two 2000x1 double vectors. Any help would be appreciated. Note: The shading was done in photoshop as I do not know how to do this in Matlab earlier.

Samatha Aleti on 31 Jan 2020
You can do this by finding the points of intersection of the curve(y1) and the line(y2). Let the intersection points be “[x1,y1] and[x2,y2]. You can find the area using "integral" function.Here is a sample code:
x1 = 1; % Let
x2 = 5; % Let
xmin = min(x1,x2);
xmax = max(x1,x2);
y1 = @(x) (x.^2)+2; % Curve
y2 = @(x) 2*x; % Line
fun = @(x) ((x.^2)+2 - 2*x); % y1-y2
area = integral(fun,xmin,xmax);