![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/450383/image.png)
Determine the area between f(x) and the x axis on the interval [-1,8] by using the zeros.
2 views (last 30 days)
Show older comments
Hi there
I need to determine the area between f(x) and the x axis on the interval [-1,8] by using the zeros.
f(x) = 2*x.^3 -15.4*x.^2 +2.7*x +2.25
I have gotten the zeros as -0.3 : 0.5 : 7.5 ...
Please note that this is not determining the area under f(x) NOR is it the definite intergral of f(x).
0 Comments
Answers (1)
Image Analyst
on 6 Dec 2020
Edited: Image Analyst
on 6 Dec 2020
Try this:
numElements = 50000;
x = linspace(-1, 8, numElements);
fx = 2*x.^3 - 15.4*x.^2 + 2.7*x + 2.25;
plot(x, fx, 'b-', 'LineWidth', 2);
grid on;
yline(0, 'LineWidth', 2); % Draw x axis.
xlabel('x', 'FontSize', 20);
ylabel('f(x)', 'FontSize', 20);
aboveZero = fx >= 0;
deltaX = x(2) - x(1)
areaAboveZero = sum(fx(aboveZero)) * deltaX
You get
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/450383/image.png)
deltaX =
0.000180003600071976
areaAboveZero =
16.1831197098485
If you need it more accurately than that you can either increase the number of points or use trapz(), but I think for most purposes, this should be accurate enough.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!