Calculation of area between a line based on data points, and a function
1 view (last 30 days)
Show older comments
Emelie Persson
on 12 Mar 2015
Commented: Star Strider
on 23 Mar 2015
I have an area I want to calculate. It's situated between a line of ~750 data Points and a straight line based on two data Points. It's illustrated by the middle graph in the attached image. (It is based on the upper parts of the first and third graph)
I have managed to calculate the area of the first graph in the Picture, by using trapz. The line is based on ~2000 data Points.
Its easy to find the function of the straight line, but I'd rather not fit the other data points into a function.
Is it possible to somehow use both trapz and integral to find this area?
0 Comments
Accepted Answer
Star Strider
on 12 Mar 2015
You only need to know the slope of the line, since it has an intercept at zero.
Example:
f1 = @(x) exp(-((x-50)./10).^2)*25E+7; % Create Function
f2 = @(x) 2*x; % Zero Intercept, Slope = 2*x
x = linspace(0, 9.52); % For Plotting
difn = @(x) f2(x)-f1(x); % Subtract Functions
a = integral(difn, min(x), max(x)); % Area Between Line And Curve
figure(1)
plot(x, f1(x))
hold on
plot(x, f2(x))
patch([x x], [f1(x) f2(x)], 'b') % Plot Area
hold off
text(4, 4.5, sprintf('Area = %.2f', a), 'Color','y')
2 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!