help me, why is it invalid use of operator?

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

回答(1 个)

David Hill
David Hill 2020-7-21
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 个评论
David Hill
David Hill 2020-7-21
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 2020-7-21
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)));

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by