My Math Forum  

Go Back   My Math Forum > Math Forums > Math Software

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


Reply
 
LinkBack Thread Tools Display Modes
November 8th, 2011, 07: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 fpname...help please?
wale06 is offline  
 
December 22nd, 2011, 10: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.


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
maxiim is offline  
Reply

  My Math Forum > Math Forums > Math Software

Tags
corrected, matlab, rule, trapezoidal



Thread Tools
Display Modes


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





Copyright © 2014 My Math Forum. All rights reserved.