SlideShare a Scribd company logo
1 of 9
PRACTICAL
Name- Saloni Singhal
M.Sc. (Statistics) II-Sem.
Roll No: 2046398
Course- MATH-409 L
Numerical Analysis Lab
Submitted To: Dr. S.C. Pandey
OBJECTIVE
1. Create an M-file to implement
Trapezoidal Rule.
2. Verify Error can be reduced by
breaking the curve into parts.
Theory
Under this rule, the area under a curve is evaluated by dividing the
total area into little trapezoids rather than rectangles.
Let f(x) be continuous on [a,b]. We partition the interval [a,b] into n
equal subintervals, each of width Δx= b−a/n,
such that a=x0<x1<x2…<xn=b
Trapezoidal rule is given by:
As n approaches infinity it becomes equal to the given definite
integral
Error in Trapezoidal
Rule
Local Error
Global Error
Global Error O(h2)is sum total of all error and is
of an order less than Local error O(h3)
Script
File
a=input('Enter lower limit: ');
b=input('Enter upper limit: ');
if ~(b>a)
error('upper bound must be greater than lower');
end
f=@(x)exp(x) %function
trueval=integral(f,a,b)
err=zeros(1,5)
for i=1:5
n=2^i
[I,xv,fv]=trap(n,a,b)
err(i)=abs(I-trueval)
plot(xv,fv)
hold on
end
hold off
%plot([2,4,8,16,32],err)
function [I,xv,fv]=trap(n,a,b)
f=@(x)sin(x)
h=(b-a)/n;
%average of first and last term
s=0.5*(f(a)+f(b));
fv=zeros(1,n+1);
xv=zeros(1,n+1);
fv(1)=f(a);
xv(1)=a;
fv(n+1)=f(b);
xv(n+1)=b;
%summation of middle terms
for i=1:n-1
s=s+f(a+i*h);
fv(i+1)=f(a+i*h);
xv(i+1)=a+i*h;
%final integral value
end
I=h*s
end
Output
Plot of approximation of no. of
sub-intervals vs functions
Plot of no. of subintervals vs error
Error for n=2,4,8,16,32
Conclusion
• Error is dependent upon the curvature of the actual
function as well as the distance between the points.
• Error can thus, be reduced by breaking the curve into
parts i.e. increasing no of subintervals
• The simplicity of the trapezoidal rule makes it an ideal
for many numerical integration tasks. Also, the
trapezoidal rule is exact for piecewise linear curves
such as an ROC curve
Caveats
• the coefficients only make sense when the abscissae are
evenly spaced, limiting the use of the approximation to
evenly spaced function evaluations.
• A drawback of this rule is since it uses straight line approx.
function, error is related to the second derivative of the
function.
• More complicated approximation formulas can improve the
accuracy for curves - these include using (a) 2nd and (b) 3rd
order polynomials.
• The formulas that result from taking the integrals under these
polynomials are called Simpson’s rules as discussed further

More Related Content

Similar to Trapezoidal Rule

A Robust Method Based On LOVO Functions For Solving Least Squares Problems
A Robust Method Based On LOVO Functions For Solving Least Squares ProblemsA Robust Method Based On LOVO Functions For Solving Least Squares Problems
A Robust Method Based On LOVO Functions For Solving Least Squares ProblemsDawn Cook
 
Bisection method in maths 4
Bisection method in maths 4Bisection method in maths 4
Bisection method in maths 4Vaidik Trivedi
 
Steady state CFD analysis of C-D nozzle
Steady state CFD analysis of C-D nozzle Steady state CFD analysis of C-D nozzle
Steady state CFD analysis of C-D nozzle Vishnu R
 
Numerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi schemeNumerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi schemexingangahu
 
Instance based learning
Instance based learningInstance based learning
Instance based learningswapnac12
 
Trust Region Algorithm - Bachelor Dissertation
Trust Region Algorithm - Bachelor DissertationTrust Region Algorithm - Bachelor Dissertation
Trust Region Algorithm - Bachelor DissertationChristian Adom
 
Propagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace ReductionPropagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace ReductionMohammad
 
Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...guest31063e
 
Aristotle boyd martin-peci_poster_2017
Aristotle boyd martin-peci_poster_2017Aristotle boyd martin-peci_poster_2017
Aristotle boyd martin-peci_poster_2017Aristotle Boyd-Martin
 
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...SSA KPI
 
An efficient hardware logarithm generator with modified quasi-symmetrical app...
An efficient hardware logarithm generator with modified quasi-symmetrical app...An efficient hardware logarithm generator with modified quasi-symmetrical app...
An efficient hardware logarithm generator with modified quasi-symmetrical app...IJECEIAES
 

Similar to Trapezoidal Rule (20)

A Robust Method Based On LOVO Functions For Solving Least Squares Problems
A Robust Method Based On LOVO Functions For Solving Least Squares ProblemsA Robust Method Based On LOVO Functions For Solving Least Squares Problems
A Robust Method Based On LOVO Functions For Solving Least Squares Problems
 
Bisection method in maths 4
Bisection method in maths 4Bisection method in maths 4
Bisection method in maths 4
 
MUMS: Transition & SPUQ Workshop - Gradient-Free Construction of Active Subsp...
MUMS: Transition & SPUQ Workshop - Gradient-Free Construction of Active Subsp...MUMS: Transition & SPUQ Workshop - Gradient-Free Construction of Active Subsp...
MUMS: Transition & SPUQ Workshop - Gradient-Free Construction of Active Subsp...
 
Steady state CFD analysis of C-D nozzle
Steady state CFD analysis of C-D nozzle Steady state CFD analysis of C-D nozzle
Steady state CFD analysis of C-D nozzle
 
Numerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi schemeNumerical disperison analysis of sympletic and adi scheme
Numerical disperison analysis of sympletic and adi scheme
 
Unit4
Unit4Unit4
Unit4
 
Integration
IntegrationIntegration
Integration
 
Instance based learning
Instance based learningInstance based learning
Instance based learning
 
1519 differentiation-integration-02
1519 differentiation-integration-021519 differentiation-integration-02
1519 differentiation-integration-02
 
RS
RSRS
RS
 
Es272 ch6
Es272 ch6Es272 ch6
Es272 ch6
 
Trust Region Algorithm - Bachelor Dissertation
Trust Region Algorithm - Bachelor DissertationTrust Region Algorithm - Bachelor Dissertation
Trust Region Algorithm - Bachelor Dissertation
 
L 4 4
L 4 4L 4 4
L 4 4
 
robio-2014-falquez
robio-2014-falquezrobio-2014-falquez
robio-2014-falquez
 
Propagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace ReductionPropagation of Error Bounds due to Active Subspace Reduction
Propagation of Error Bounds due to Active Subspace Reduction
 
Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...Normalized averaging using adaptive applicability functions with applications...
Normalized averaging using adaptive applicability functions with applications...
 
www.ijerd.com
www.ijerd.comwww.ijerd.com
www.ijerd.com
 
Aristotle boyd martin-peci_poster_2017
Aristotle boyd martin-peci_poster_2017Aristotle boyd martin-peci_poster_2017
Aristotle boyd martin-peci_poster_2017
 
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
Efficient Solution of Two-Stage Stochastic Linear Programs Using Interior Poi...
 
An efficient hardware logarithm generator with modified quasi-symmetrical app...
An efficient hardware logarithm generator with modified quasi-symmetrical app...An efficient hardware logarithm generator with modified quasi-symmetrical app...
An efficient hardware logarithm generator with modified quasi-symmetrical app...
 

More from Saloni Singhal

Finite Difference Method
Finite Difference MethodFinite Difference Method
Finite Difference MethodSaloni Singhal
 
Simpson's Three-Eighth Method
Simpson's Three-Eighth MethodSimpson's Three-Eighth Method
Simpson's Three-Eighth MethodSaloni Singhal
 
Newton Forward Interpolation
Newton Forward InterpolationNewton Forward Interpolation
Newton Forward InterpolationSaloni Singhal
 
Newton Backward Interpolation
Newton Backward InterpolationNewton Backward Interpolation
Newton Backward InterpolationSaloni Singhal
 
Lagrange Interpolation
Lagrange InterpolationLagrange Interpolation
Lagrange InterpolationSaloni Singhal
 
Forward & Backward Differenece Table
Forward & Backward Differenece TableForward & Backward Differenece Table
Forward & Backward Differenece TableSaloni Singhal
 
Newton's Raphson method
Newton's Raphson methodNewton's Raphson method
Newton's Raphson methodSaloni Singhal
 
Fixed Point Interation
Fixed Point InterationFixed Point Interation
Fixed Point InterationSaloni Singhal
 
MARLAB codes for Gauss Seidel
MARLAB codes for Gauss SeidelMARLAB codes for Gauss Seidel
MARLAB codes for Gauss SeidelSaloni Singhal
 
MATLAB Codes for Jacobi method
MATLAB Codes for Jacobi methodMATLAB Codes for Jacobi method
MATLAB Codes for Jacobi methodSaloni Singhal
 
Gauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxGauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxSaloni Singhal
 
Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)Saloni Singhal
 

More from Saloni Singhal (20)

Finite Difference Method
Finite Difference MethodFinite Difference Method
Finite Difference Method
 
Runge Kutta Method
Runge Kutta MethodRunge Kutta Method
Runge Kutta Method
 
Euler Method
Euler MethodEuler Method
Euler Method
 
Simpson's Three-Eighth Method
Simpson's Three-Eighth MethodSimpson's Three-Eighth Method
Simpson's Three-Eighth Method
 
Simpson One-Third
Simpson One-ThirdSimpson One-Third
Simpson One-Third
 
Newton Forward Interpolation
Newton Forward InterpolationNewton Forward Interpolation
Newton Forward Interpolation
 
Newton Backward Interpolation
Newton Backward InterpolationNewton Backward Interpolation
Newton Backward Interpolation
 
Lagrange Interpolation
Lagrange InterpolationLagrange Interpolation
Lagrange Interpolation
 
Forward & Backward Differenece Table
Forward & Backward Differenece TableForward & Backward Differenece Table
Forward & Backward Differenece Table
 
Bisection Method
Bisection MethodBisection Method
Bisection Method
 
Newton's Raphson method
Newton's Raphson methodNewton's Raphson method
Newton's Raphson method
 
Fixed Point Interation
Fixed Point InterationFixed Point Interation
Fixed Point Interation
 
Power Method
Power MethodPower Method
Power Method
 
Eigen Show
Eigen ShowEigen Show
Eigen Show
 
Inverse Power Method
 Inverse Power Method Inverse Power Method
Inverse Power Method
 
MARLAB codes for Gauss Seidel
MARLAB codes for Gauss SeidelMARLAB codes for Gauss Seidel
MARLAB codes for Gauss Seidel
 
MATLAB Codes for Jacobi method
MATLAB Codes for Jacobi methodMATLAB Codes for Jacobi method
MATLAB Codes for Jacobi method
 
L-U Decomposition
L-U DecompositionL-U Decomposition
L-U Decomposition
 
Gauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptxGauss Elimination (without pivot).pptx
Gauss Elimination (without pivot).pptx
 
Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)Gauss Elimination (With Partial Pivot)
Gauss Elimination (With Partial Pivot)
 

Recently uploaded

Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxolyaivanovalion
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxolyaivanovalion
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAroojKhan71
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxMohammedJunaid861692
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 

Recently uploaded (20)

Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
VidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptxVidaXL dropshipping via API with DroFx.pptx
VidaXL dropshipping via API with DroFx.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptx
 
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al BarshaAl Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
Al Barsha Escorts $#$ O565212860 $#$ Escort Service In Al Barsha
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 

Trapezoidal Rule

  • 1. PRACTICAL Name- Saloni Singhal M.Sc. (Statistics) II-Sem. Roll No: 2046398 Course- MATH-409 L Numerical Analysis Lab Submitted To: Dr. S.C. Pandey
  • 2. OBJECTIVE 1. Create an M-file to implement Trapezoidal Rule. 2. Verify Error can be reduced by breaking the curve into parts.
  • 3. Theory Under this rule, the area under a curve is evaluated by dividing the total area into little trapezoids rather than rectangles. Let f(x) be continuous on [a,b]. We partition the interval [a,b] into n equal subintervals, each of width Δx= b−a/n, such that a=x0<x1<x2…<xn=b Trapezoidal rule is given by: As n approaches infinity it becomes equal to the given definite integral
  • 4. Error in Trapezoidal Rule Local Error Global Error Global Error O(h2)is sum total of all error and is of an order less than Local error O(h3)
  • 5. Script File a=input('Enter lower limit: '); b=input('Enter upper limit: '); if ~(b>a) error('upper bound must be greater than lower'); end f=@(x)exp(x) %function trueval=integral(f,a,b) err=zeros(1,5) for i=1:5 n=2^i [I,xv,fv]=trap(n,a,b) err(i)=abs(I-trueval) plot(xv,fv) hold on end hold off %plot([2,4,8,16,32],err) function [I,xv,fv]=trap(n,a,b) f=@(x)sin(x) h=(b-a)/n; %average of first and last term s=0.5*(f(a)+f(b)); fv=zeros(1,n+1); xv=zeros(1,n+1); fv(1)=f(a); xv(1)=a; fv(n+1)=f(b); xv(n+1)=b; %summation of middle terms for i=1:n-1 s=s+f(a+i*h); fv(i+1)=f(a+i*h); xv(i+1)=a+i*h; %final integral value end I=h*s end
  • 6. Output Plot of approximation of no. of sub-intervals vs functions
  • 7. Plot of no. of subintervals vs error Error for n=2,4,8,16,32
  • 8. Conclusion • Error is dependent upon the curvature of the actual function as well as the distance between the points. • Error can thus, be reduced by breaking the curve into parts i.e. increasing no of subintervals • The simplicity of the trapezoidal rule makes it an ideal for many numerical integration tasks. Also, the trapezoidal rule is exact for piecewise linear curves such as an ROC curve
  • 9. Caveats • the coefficients only make sense when the abscissae are evenly spaced, limiting the use of the approximation to evenly spaced function evaluations. • A drawback of this rule is since it uses straight line approx. function, error is related to the second derivative of the function. • More complicated approximation formulas can improve the accuracy for curves - these include using (a) 2nd and (b) 3rd order polynomials. • The formulas that result from taking the integrals under these polynomials are called Simpson’s rules as discussed further