help me, why is it invalid use of operator?

1 visualización (últimos 30 días)
Jefferson Pons
Jefferson Pons el 21 de Jul. de 2020
Comentada: David Hill el 21 de Jul. de 2020
can you guys help me? this is the code im having problem with:
% Simpson's 1/3 Rule for finding integration of x
the function that i want to use is this:
please help me. thank you!

Respuestas (1)

David Hill
David Hill el 21 de Jul. de 2020
Not sure if you have additional constraints, but if your functions are all polynomials, the polyint function works well.
p=[-.0729,1.171,-13.8,4,-1];
intP=diff(polyval(polyint(p),[a,b]));%where a and b are the lower and upper bounds
  2 comentarios
David Hill
David Hill el 21 de Jul. de 2020
f=@(x)-.0729*x.^4+1.171*x.^3-13.8*x.^2+4*x-1;%here is how you write the function
David Hill
David Hill el 21 de Jul. de 2020
Where a,b,and n are input like above
f=@(x)-.0729*x.^4+1.171*x.^3-13.8*x.^2+4*x-1;
x=linspace(a,b,n+1);
y=f(x);
intF=(b-a)/3/n*(f(a)+f(b)+4*sum(y(1:2:end))+2*sum(y(2:2:end)));

Iniciar sesión para comentar.

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by