MATLAB : Numerical Differention and Integration
-
Upload
ainul-islam -
Category
Engineering
-
view
171 -
download
20
Transcript of MATLAB : Numerical Differention and Integration
![Page 1: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/1.jpg)
AHSANULLAH UNIVERSITY OF SCIENCE AND TECHNOLOGY
EEE 3110NUMERICAL TECHNIQUE LABORATORY
![Page 2: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/2.jpg)
![Page 3: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/3.jpg)
PRESENTED BY :
AINUL ISLAM (ID 12-02-05-065)
SHADMAN SAKIB AOYON (ID 12-02-05-060)
MIRZA SHAMIM ARMAN (ID 12-02-05-072)
TAUHIDUR RAHMAN AKIF (ID 12-02-05-062)
KAZI WALIDA AFROZE (ID 12-02-05-079)
![Page 4: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/4.jpg)
CONTENTS:
• INTRODUCTION TO NUMERICAL DIFFERENTIATION
• FORWARD DIFFERENCE FORMULA
• CENTRAL DIFFERENCE FORMULA
• RICHARDSON’S EXTRAPOLATION
• INTRODUCTION TO NUMERICAL INTEGRATION
• TRAPEZOIDAL RULE
• SIMPSON’S RULE
![Page 5: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/5.jpg)
Numerical Differentiation : Numerical differentiation deals with the following problem : we are given the functiony = f (x) and wish to obtain one of its derivatives at the point x = xk. The term “given”means that we either have an algorithm for computing the function, or possess aset of discrete data points (xi , yi ), i = 1, 2, . . . , n. In either case, we have access to afinite number of (x, y) data pairs from which to compute the derivative. If you suspectby now that numerical differentiation is related to interpolation, you are right—onemeans of finding the derivative is to approximate the function locally by a polynomialand then differentiate it. An equally effective tool is the Taylor series expansion off (x) about the point xk. The latter has the advantage of providing us with informationabout the error involved in the approximation.Numerical differentiation is not a particularly accurate process. It suffers froma conflict between round off errors (due to limited machine precision) and errorsinherent in interpolation. For this reason, a derivative of a function can never becomputed with the same precision as the function itself
![Page 6: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/6.jpg)
Taylor series expansion can be used to generate high-accuracy formulas for derivatives by using linear algebra to combine the expansion around several points.
We will discuss three categories of formula:
• Forward difference formula
•Centered difference formula
•Richardson Extrapolation formula
![Page 7: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/7.jpg)
![Page 8: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/8.jpg)
FORWARD DIFFERENCE FORMULA
![Page 9: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/9.jpg)
EXAMPLE :Given that f(x)=(sin x) and h=.001 find the first derivative f’(x) using forward difference formula in MATLAB :Code :-clear all;close all;clc;h=.001;x=0:(.001):2*pi;f=inline(‘sin (x)’)q=f(x)d=f(x+h)a=((d-q)/h)plot(x,a)da
![Page 10: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/10.jpg)
![Page 11: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/11.jpg)
![Page 12: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/12.jpg)
CENTRAL DIFFERENCE FORMULA :
![Page 13: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/13.jpg)
![Page 14: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/14.jpg)
Richardson Extrapolation
• As with integration, the Richardson extrapolation can be used to combine two lower-accuracy estimates of the derivative to produce a higher-accuracy estimate.
• For the cases where there are two O(h2) estimates and the interval is halved (h2=h1/2), an improved O(h4) estimate may be formed using:
• For the cases where there are two O(h4) estimates and the interval is halved (h2=h1/2), an improved O(h6) estimate may be formed using:
€
D=4
3D(h2)−
1
3D(h1)
€
D=1615
D(h2)−115
D(h1)
![Page 15: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/15.jpg)
Numerical integration, also known as quadrature, is intrinsically a much more accurateprocedure than numerical differentiation. Quadrature approximates the definiteIntegral. Numerical integration is a widely encountered problem in economics.All rules of quadrature are derived from polynomial interpolation of theintegrand. Therefore, they work best if f (x) can be approximated by a polynomial.
Methods of numerical integration can be divided into two groups: 1.Newton–Cotes formulas (The Trapezoidal Rule and Simpson’s Rule)2.Gaussian quadrature.
Newton–Cotes formulas are characterized byequally spaced abscissas, and include well-known methods such as the trapezoidalrule and Simpson’s rule. They are most useful if f (x) has already been computed atequal intervals, or can be computed at low cost. Since Newton–Cotes formulas arebased on local interpolation, they require only a piecewise fit to a polynomial
INTRODUCTION TO NUMERICAL INTEGRATION :
![Page 16: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/16.jpg)
The trapezoidal rule uses trapezoids to approximate area, which usually is a much more accurate approximation, even with just a few subintervals.Notice that the height of the trapezoids will actually be Δx (horizontal) and bases will be the parallel f(xi) (vertical) on each side of the subinterval. ( )
trapezoid1 2A =
2
b bh
+×
THE TRAPEZOIDAL RULE
![Page 17: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/17.jpg)
What is Trapezoidal Method ?
1
![Page 18: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/18.jpg)
Observe that the coefficients are 1, 2, 2, 2, 2, . . . 2, 1
TRAPEZOIDAL RULE
![Page 19: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/19.jpg)
4
![Page 20: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/20.jpg)
The area of the first trapezoid would be
0 1( ) ( )
2
f x f x b a
n
+ − × ÷
0 1 11 2( ) ( ) ( ) ( )( ) ( )
2 2 2n nf x f x f x f xf x f xb a
n−+ ++− + + ×× × + ÷ Area =
and then total area would be
Letting the number of trapezoids n approach infinity, you improve the approximation to the exact answer.
( ) ( ) ( )0 1 1 2 1lim ( ) ( ) ( ) ( ) ( ) ( )2 n nn
b af x f x f x f x f x f x
n −→∞
− + + + + ×× × + +
![Page 21: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/21.jpg)
There are many alternatives to the trapezoidal rule, but this method deserves attention because of :
•Its ease of use
•The trapezoidal rule has faster convergence.
•Moreover, the trapezoidal rule tends to become extremely accurate than periodic functions
•Powerful convergence properties
•Straightforward analysis
Advantages
7
![Page 22: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/22.jpg)
Thomas Simpson (1710-1761) used second-degree polynomials (a section of a quadratic) to approximate the graph for each subinterval.Before we get into Simpson’s Rule, we need to list a theorem for evaluating integrals of polynomials of degree 2 or less.
THE SIMPSON’S RULE
![Page 23: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/23.jpg)
THE SIMPSON’S RULE
Notice the coefficients are 1, 4, 2, 4, . . . 2, 4, 1
![Page 24: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/24.jpg)
EXAMPLE OF SIMPSON’S RULE :Given, f=(cos x); n=12; low value=-1; high value=2;Integrate the function over the values of x using Simpson’s 1/3 rule : clear all; close all; clc; h= -0.1; n=12; sum=0; f=inline(‘ cos (x)’); sum=sum + f(a) for i=2 : 2 :n ; x(i)=a + i*n; sum=sum+4*f(x(i)) end for i =3 : 2 : (n-1) ; x( i )=a + i *n; sum=sum+2*f(x(i)) end sum=sum + f(a +n * h) p=(sum*h)/3
![Page 25: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/25.jpg)
ERRORS :These two expressions tell how much of an error you can expect to get using either the Trapezoidal Rule or Simpson’s Rule.
![Page 26: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/26.jpg)
http://en.wikipedia.org
www.google.com
http://slideshare.com
And various relevant websites
References
15
![Page 27: MATLAB : Numerical Differention and Integration](https://reader031.fdocuments.in/reader031/viewer/2022031714/55a95e051a28ab90138b467d/html5/thumbnails/27.jpg)
Thank You