My Math Forum  

Go Back   My Math Forum > Math Forums > Math Software

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

LinkBack Thread Tools Display Modes
November 8th, 2011, 06:36 PM   #1
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 please?
wale06 is offline  
December 22nd, 2011, 09:08 AM   #2
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

where I compute the integral from 0,1.

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)));

surf = fint(end)

% Built in matlab command trapz: 

trapo = trapz(X,Y)

maxiim is offline  

  My Math Forum > Math Forums > Math Software

corrected, matlab, rule, trapezoidal

Search tags for this page
Click on a term to search for related topics.
Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trapezoidal rule jones1234 Calculus 0 December 30th, 2012 11:11 AM
Trapezoidal Rule aaron-math Calculus 4 October 2nd, 2011 05:37 PM
trapezoidal rule strawberryPK Calculus 1 January 18th, 2011 02:42 PM
Simpsons rule,Trapezoidal rule,check please manich44 Algebra 3 February 17th, 2010 09:23 AM
Trapezoidal rule William_33 Applied Math 0 December 31st, 1969 04:00 PM

Copyright © 2017 My Math Forum. All rights reserved.