function outv=trap1step(a,b,n,oldval) %outv=trap1step(a,b,n,oldval) % %This routine calculates one step of the Trapeziodal Method to %approximate the definite integral of a function, myf, over the %interval [a,b], using n subintervals. % %It assumes that a previous approximation using n/2 subintervals %has been performed and the result is in the parameter oldval. % %Inputs: % a,b - the endpoints of the interval of integration. % n - the number of subintervals used in the approximation. % oldval - the Trapeziodal Approximation using n/2 subintervals. % myf - not listed, a user defined function (M-file called myf.m) % %Outputs: % outv - the approximation. global count; h=(b-a)/n; %h is the length of the subinterval. ii=[1:2:n-1]; %ii is an index of the "new" nodes. xx=a+h*ii; %xx is the values of the "new" nodes. outv=oldval/2+h*sum(myf(xx)); %count=count+length(ii);