clc;
close all;
f=input("Enter function");
a=input("Enter lower limit");
b=input("Enter upper limit");
n=input("Enter no of subintervals");
h=(b-a)/n;
sum=0;
for i=1:n-1
x=a+h*i;
if rem(i,2)==0
sum=sum+2*f(x);
else
sum=sum+4*f(x);
end
end
sum=sum+f(a)+f(b);
sum=sum*(h/3)
Cite As
Akshay (2024). na-lab-simpsons (https://www.mathworks.com/matlabcentral/fileexchange/120428-na-lab-simpsons), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2022b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.