Lecture 26: Numerical Integration Trapezoid rule Simpson's rule Simpson's 3/8 rule Boole’s rule Newton-Cotes Formulas.

Slides:



Advertisements
Similar presentations
MATLAB Tutorial ECE 002 Professor S. Ahmadi.
Advertisements

Numerical Integration
Lecture 5 Fixed point iteration Download fixedpoint.m From math.unm.edu/~plushnik/375.
Computational Physics Numerical Integration Dr. Guy Tel-Zur Tulips by Anna Cervova, publicdomainpictures.net.
ES 240: Scientific and Engineering Computation. Chapter 17: Numerical IntegrationIntegration  Definition –Total area within a region –In mathematical.
Quadrature. 二阶 : 中点公式 : 梯形公式 : 四阶公式 : Simpson’s 1/3 rd Rule.
Lecture 14: Newton’s method for system of two nonlinear equations Function newton2d01 Set initial (x,y) point, maximum number of iterations, and convergence.
1 Chapter 5 Numerical Integration. 2 A Review of the Definite Integral.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Prentice Hall Trapezoidal Rule Section 5.5.
Chapter 7 Numerical Differentiation and Integration
Numerical Integration
Newton-Cotes Integration Formula
Lecture 3: Integration. Integration of discrete functions
MANE 4240 & CIVL 4240 Introduction to Finite Elements Numerical Integration in 1D Prof. Suvranu De.
MECH300H Introduction to Finite Element Methods Lecture 2 Review.
NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.
Lecture 28: Comparison of different numerical integrators 1.Adaptive Simpson’s and Trapezoid Rules 2. Romberg Integration 3. Adaptive Gaussian Quadrature.
Area of a single trapezoid = h
1 Chapter 5 Numerical Integration. 2 A Review of the Definite Integral.
Numerical Integration
Lecture 19 - Numerical Integration CVEN 302 July 22, 2002.
1 Chapter 7 NUMERICAL INTEGRATION. 2 PRELIMINARIES We use numerical integration when the function f(x) may not be integrable in closed form or even in.
1 Numerical Analysis Lecture 12 Numerical Integration Dr. Nader Okasha.
Introduction to Numerical Analysis I
Lecture 19 – Numerical Integration 1 Area under curve led to Riemann sum which led to FTC. But not every function has a closed-form antiderivative.
4.6 Numerical Integration Trapezoid and Simpson’s Rules.
4.6 Numerical Integration. The Trapezoidal Rule One method to approximate a definite integral is to use n trapezoids.
Dr. Mubashir Alam King Saud University. Outline Numerical Integration Trapezoidal and Simpson’s Rules (5.1)
1 Numerical Integration Section Why Numerical Integration? Let’s say we want to evaluate the following definite integral:
MECH345 Introduction to Finite Element Methods Chapter 1 Numerical Methods - Introduction.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Prentice Hall 5.5 Trapezoidal Rule.
Introduction to Numerical Analysis I
6. Numerical Integration 6.1 Definition of numerical integration. 6.2 Reasons to use numerical integration. 6.3 Formulas of numerical Integration. 6.4.
數值方法 2008, Applied Mathematics NDHU 1 Numerical Differentiation.
Clicker Question 1 What is lim x->  ln(x) /  x ? – A. 0 – B.  – C. 1 – D. -  – E. 2.
Clicker Question 1 What is ? (Hint: u-sub) – A. ln(x – 2) + C – B. x – x 2 + C – C. x + ln(x – 2) + C – D. x + 2 ln(x – 2) + C – E. 1 / (x – 2) 2 + C.
Quadrature – Concepts (numerical integration) Don Allen.
數值方法 2008, Applied Mathematics NDHU 1 Numerical Integration.
Numerical Integration
Air Force Admin College, Coimbatore
NUMERICAL DIFFERENTIATION Forward Difference Formula
Lecture 19 – Numerical Integration
Use the Midpoint Rule to approximate the given integral with the specified value of n. Compare your result to the actual value and find the error in the.
Approximate Integration
Midpoint and Trapezoidal Rules
Numerical Analysis Lecture 42.
MTH1170 Numeric Integration
5.5 Trapezoidal Rule.
Area of a single trapezoid = h
Integration with Unequal Segments
Techniques of Integration
Numerical Analysis Lecture 27.
NUMERICAL DIFFERENTIATION AND INTEGRATION
NUMERICAL INTEGRATION
MATH 2140 Numerical Methods
Composite Numerical Integration
Elements of Numerical Integration
Elements of Numerical Integration
Area of a single trapezoid = h
WELCOME TO MY CLASS NUMERICAL METHOD Name : Masduki
MATH 174: NUMERICAL ANALYSIS I
Arc Length … x y a b xi ... Pi P0 P1 Pn
Area of a single trapezoid = h
Numerical Computation and Optimization
Techniques of Integration
MATH 2140 Numerical Methods
Numerical Integration
Air Force Admin College, Coimbatore
Elements of Numerical Integration
Presentation transcript:

Lecture 26: Numerical Integration Trapezoid rule Simpson's rule Simpson's 3/8 rule Boole’s rule Newton-Cotes Formulas

trapezoid1.m trapezoid1test.m function f1=trapezoid1(func1,a,b,n) %Integration function func1 %using composite trapezoid rule at n points between a and b h=(b-a)/n; f1=func1(a)/2; for i=1:n-1 f1=f1+func1(a+i*h); end f1=f1+func1(b)/2; f1=h*f1;

%examples of use of function f1=trapezoid1(func1,a,b,n) %Integration function func1 %using composite trapezoid rule at n points between a and b a=1; b=5; f1=inline('exp(-x)') disp(['a=',num2str(a),' b=',num2str(b)]) %display limits of integration intexact=-exp(-b)+exp(-a); i=1:10; nvec=2.^(i); for i=1:length(nvec) f1int=trapezoid1(f1,a,b,nvec(i)); disp(['n=',num2str(nvec(i)),' Error in composite trapezod rule =',num2str(f1int-intexact)]); %display value of function f(x) end

>> trapezoid1test f1 = Inline function: f1(x) = exp(-x) a=1 b=5 n=2 Error in composite trapezod rule = n=4 Error in composite trapezod rule = n=8 Error in composite trapezod rule = n=16 Error in composite trapezod rule = n=32 Error in composite trapezod rule = n=64 Error in composite trapezod rule = n=128 Error in composite trapezod rule =2.9389e-005 n=256 Error in composite trapezod rule =7.3474e-006 n=512 Error in composite trapezod rule =1.8369e-006 n=1024 Error in composite trapezod rule =4.5922e-007

a=0; b=2*pi; f1=inline('exp(sin(x)^2)') disp(['a=',num2str(a),' b=',num2str(b)]) %display limits of integration intexact=trapezoid1(f1,a,b,200); i=1:5; nvec=2.^(i); for i=1:length(nvec) f1int=trapezoid1(f1,a,b,nvec(i)); disp(['n=',num2str(nvec(i)),' Error in composite trapezod rule =',num2str(f1int-intexact)]); %display value of function f(x) end

f1 = Inline function: f1(x) = exp(sin(x)^2) a=0 b= n=2 Error in composite trapezod rule = n=4 Error in composite trapezod rule = n=8 Error in composite trapezod rule = n=16 Error in composite trapezod rule =7.8954e-009 n=32 Error in composite trapezod rule = e-015 f1 = Inline function: f1(x) = exp(sin(x)^2) a=0 b= n=2 Error in composite trapezod rule = n=4 Error in composite trapezod rule = n=8 Error in composite trapezod rule = n=16 Error in composite trapezod rule = n=32 Error in composite trapezod rule =8.0649e-005

a=0; b=pi/4; f1=inline('exp(sin(x)^2)') disp(['a=',num2str(a),' b=',num2str(b)]) %display limits of integration intexact=trapezoid1(f1,a,b,200); i=1:5; nvec=2.^(i); for i=1:length(nvec) f1int=trapezoid1(f1,a,b,nvec(i)); disp(['n=',num2str(nvec(i)),' Error in composite trapezod rule =',num2str(f1int-intexact)]); %display value of function f(x) end

simpson1.m simpson1test.m function f1=simpson1(func1,a,b,n) %Integration function func1 %using composite simpson rule at n points between a and b h=(b-a)/n; f1=func1(a); for i=1:(n/2-1) f1=f1+4*func1(a+(2*i-1)*h)+2*func1(a+(2*i)*h); end f1=f1+4*func1(a+(n-1)*h)+func1(b); f1=(h/3)*f1;

%examples of use of function f1=simpson1(func1,a,b,n) %Integration function func1 %using composite Simpson's rule at n points between a and b; n must be even a=1; b=5; f1=inline('exp(-x)') disp(['a=',num2str(a),' b=',num2str(b)]) %display limits of integration intexact=-exp(-b)+exp(-a); i=1:10; nvec=2.^(i); for i=1:length(nvec) f1int=simpson1(f1,a,b,nvec(i)); disp(['n=',num2str(nvec(i)),' Error in composite trapezod rule =',num2str(f1int-intexact)]); %display value of function f(x) end …

>> simpson1test f1(x) = exp(-x) a=1 b=5 n=2 Error in composite trapezod rule = n=4 Error in composite trapezod rule = n=8 Error in composite trapezod rule = n=16 Error in composite trapezod rule =7.7793e-006 n=32 Error in composite trapezod rule =4.8892e-007 n=64 Error in composite trapezod rule =3.06e-008 n=128 Error in composite trapezod rule =1.9132e-009 n=256 Error in composite trapezod rule =1.1958e-010 n=512 Error in composite trapezod rule =7.4751e-012 n=1024 Error in composite trapezod rule =4.6674e-013 The same function with composite trapezoid rule: a=1 b=5 n=2 Error in composite trapezod rule = n=4 Error in composite trapezod rule = n=8 Error in composite trapezod rule = n=16 Error in composite trapezod rule = n=32 Error in composite trapezod rule = n=64 Error in composite trapezod rule = n=128 Error in composite trapezod rule =2.9389e-005 n=256 Error in composite trapezod rule =7.3474e-006 n=512 Error in composite trapezod rule =1.8369e-006 n=1024 Error in composite trapezod rule =4.5922e-007

Exercise Compute integral of function e^(-x^2) between a=0 and b=10 using composite trapezoid and composite Simpson’s rules for n=2,4,8,…, Compare with exact answer = sqrt(pi)/2 Use simpson1test.m as example.

>> inclass26 f1 = Inline function: f1(x) = exp(-x^2) a=0 b=10 n=2 Error in composite trapezod rule = n=4 Error in composite trapezod rule = n=8 Error in composite trapezod rule = n=16 Error in composite trapezod rule = n=32 Error in composite trapezod rule = e-012 n=64 Error in composite trapezod rule =0 n=128 Error in composite trapezod rule =2.2204e-016 n=256 Error in composite trapezod rule =5.5511e-016 n=512 Error in composite trapezod rule =0 n=1024 Error in composite trapezod rule = e-015 The same function with composite trapezoid rule: a=0 b=10 n=2 Error in composite trapezod rule = n=4 Error in composite trapezod rule = n=8 Error in composite trapezod rule = n=16 Error in composite trapezod rule =1.8863e-011 n=32 Error in composite trapezod rule =0 n=64 Error in composite trapezod rule = e-016 n=128 Error in composite trapezod rule = e-016 n=256 Error in composite trapezod rule = e-016 n=512 Error in composite trapezod rule = e-016 n=1024 Error in composite trapezod rule = e-016