function [Isic]=simpsonc(a,b,M,f,varargin) %SIMPSONC Composite Simpson numerical integration. % ISIC = SIMPSONC(A,B,M,FUN) computes an approximation % of the integral of the function FUN via the Simpson % method (using M equal subintervals). FUN accepts % real vector input x and returns a real vector value. % FUN can be either an inline function, an anonymous % function, or it can be defined by an external m-file. % ISIC = SIMPSONC(A,B,M,FUN,P1,P2,...) calls the % function FUN passing the optional parameters % P1,P2,... as FUN(X,P1,P2,...). H=(b-a)/M; x=linspace(a,b,M+1); fpm=feval(f,x,varargin{:}).*ones(1,M+1); fpm(2:end-1) = 2*fpm(2:end-1); Isic=H*sum(fpm)/6; x=linspace(a+H/2,b-H/2,M); fpm=feval(f,x,varargin{:}).*ones(1,M); Isic = Isic+2*H*sum(fpm)/3; return