function output = Simpsons(f,a,b,h)
% f - funtion
% a - This is the initial x value
% b - This is the final x value
% h - This is the step-size
x=[a:h:b]; %need to create a vector of n+1 evenly spaced points
sr=(h/3)*(f(x(1))+2*sum(f(x(3:2:end-2)))+4*sum(f(x(2:2:end)))+f(x(end)))
output=sr
end
I made this simpsons rule UDF and it works can someone just explain wihat the last line reads? I don't fully understand it. Also please let me know if this is a valid UDF for Simpsons if you do not see any errors.
0 Comments
Sign in to comment.