MATLAB: How can I determine the areas surrounded by these two plots

integrationinterpolationplot

Dear community,
I want to determine the area surrounded by these two plots. Please see the figure for more details.
My code is:
k11 = 10.5e-12;
k33 = 13.8e-12;
x = 0:1e-2:3.5;
y = q*0.5*sin(2*x)./(k11*sin(x).^2+k33*cos(x).^2);
plot(x,y,'r')
hold on
x = [0,3e-5, 7e-5, 2e-4, 6e-4, 0.002, 0.006, 0.01, 0.02, 0.03, 0.05, 0.07,...
0.09, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9, 1, 1.2, 1.4, 1.5, 1.8,2,...
2.3, 2.5, 2.9, 3.5];
y = [1.1195e6, 1.1195e+06, 1.1195e+06, 1.1195e+06, 1.1195e+06, 1.1194e+06,...
1.1192e+06, 1.1190e+06, 1.1184e+06, 1.1177e+06, 1.1161e+06, 1.1141e+06,...
1.1118e+06, 1.1105e6, 1.0930e6, 1.0669e6, 1.0321e6, 9.8841e5, 9.3568e5,...
8.7378e5, 7.2245e5, 6.3343e5, 4.3140e5, 2.0443e5, 8.5286e4, -2.7264e5,...
-4.9342e5, -7.7039e5, -9.1105e5, -1.0832e6, -1.0820e6];
plot(x,y,'o-')
end
How can I deal with this?

Best Answer

You need to determine the x-coordinates of the three crossing points of the two curves. For that purpose you can use 'fzero', taking advantage of the fact that the empirical curve segment portions will be straight lines, and you can easily see from the plot which segments they are. Having found these x-coordinates, you can then use 'trapz' to find the two quantities s1 and s2 by integrating over the appropriate range the differences between the curves at the points of the empirical curve. At the crossing points, these will be zero, of course. For more accuracy you could use 'interp1' to produce additional points to use in 'trapz'.