Determine the area between f(x) and the x axis on the interval [-1,8] by using the zeros.

2 次查看(过去 30 天)
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).

回答(1 个)

Image Analyst
Image Analyst 2020-12-6
编辑:Image Analyst 2020-12-6
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
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.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by