How do I use trap?

4 visualizaciones (últimos 30 días)
Mark Dillon
Mark Dillon el 4 de Ag. de 2015
Respondida: Al Dente el 4 de Ag. de 2015
Here is what I am working with right now:
if true
% %%Write a script to integrate a function in three different ways:
% by eyeballing it, by calling trapz with a list of points,
% and by calling integral with a function.
% Equation we’re going to integrate: y(x) = -2x^4+3x+5.
% We’re going to integrate from -1 to 1.
y = @(x) -2.*x.^4+3.*x+5;
x = -1:1;
% Plot x vs y
fplot(y, [x(1),x(end)]);
grid on
end
Now I need to use trapz to figure out how to calculate the area under the curve, but I cannot figure it out. I tried Area = trapz(x,y), but that didn't work? How to a solve this problem?

Respuesta aceptada

Al Dente
Al Dente el 4 de Ag. de 2015
area = trapz(x,y(x))
?

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by