My Math Forum MATLAB Corrected Trapezoidal Rule

 Math Software Math Software - Mathematica, Matlab, Calculators, Graphing Software

 November 8th, 2011, 07:36 PM #1 Newbie   Joined: Oct 2011 Posts: 7 Thanks: 0 MATLAB Corrected Trapezoidal Rule I have this function: function y = corrtrap(fname, fpname, a, b) % Corrected trapezoidal rule y. % fname - the m-file used to evaluate the integrand, % fpname - the m-file used to evaluate the first derivative % of the integrand, % a,b - endpoinds of the interval of integration. h = b - a; y = (h/2).*(feval(fname,a) + feval(fname,b))+ (h.^2)/12.*( ... feval(fpname,a) - feval(fpname,b)); Not sure how to compute the m-files for fname and fpname...help please?
 December 22nd, 2011, 10:08 AM #2 Newbie   Joined: Dec 2011 Posts: 12 Thanks: 0 Re: MATLAB Corrected Trapezoidal Rule Well, you should give more information. You could do something like this, where I assumed a sample function $-\ln{(x)}\sinh{(x)}$ where I compute the integral from 0,1. Code: del = sqrt(eps); % derivative step fname = @(x) -log(x)*sinh(x); % anonymous function fprime = @(x) ((-log(x+del)*sinh(x+del))+log(x)*sinh(x))/(del); %approximate derivative p=10^3; % grid points a=0.1; % left integration limit b=1; % right integration limit g=linspace(a,b,p); % discrete space fint = 0; % initial value for i=1:p-1 fint(i+1) = fint(i) + (g(i+1)-g(i))/2*(fname(g(i+1))+fname(g(i)))... - (g(i+1)-g(i))^2/12*(fprime(g(i+1))+fname(g(i))); end surf = fint(end) % Built in matlab command trapz: X=linspace(a,b); Y=-log(X).*sinh(X); trapo = trapz(X,Y) cheers

 Tags corrected, matlab, rule, trapezoidal

,

,

,

,

,

# corrected trapezoid rule matlab algorithm

Click on a term to search for related topics.
 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post jones1234 Calculus 0 December 30th, 2012 12:11 PM aaron-math Calculus 4 October 2nd, 2011 05:37 PM strawberryPK Calculus 1 January 18th, 2011 03:42 PM manich44 Algebra 3 February 17th, 2010 10:23 AM William_33 Applied Math 0 January 1st, 1970 12:00 AM

 Contact - Home - Forums - Cryptocurrency Forum - Top