help me, why is it invalid use of operator?
1 view (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
David Hill
on 21 Jul 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 Comments
David Hill
on 21 Jul 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
on 21 Jul 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)));
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!