Deriving numerical integration methods

Deriving numerical integration methods
As was the case for the composite trapezoid rule, most numerical
integration formulas have the form of a 
weighted average of values of
the integrand.
 
One approach to deriving such formulas is to replace the integrand by a polynomial.
Find the equation of the polynomial and integrate it.
For example, trapezoid rule with 2 points.
Do on board
2
This example illustrates that any numerical integration formula that evaluates the
integrand at n+1 point will be exact for a polynomial of degree n because we have
enough information to find the polynomial and integrate it analytically.
However, this approach to deriving numerical integration approximations is hard to
generalize to polynomials of degree higher than 1.
replace integrand with line
(polynomial of degree = 1)
Derive the Simpson’s rule approximation for numerical integration
Approximate the integrand by a parabola (polynomial degree 2)
Divide the range of integration into pairs of subintervals of equal width.
Develop a system of equations for the weights in the average of integrand
values by requiring the formula
to be exact for f(x) equal to 1, x, and x
2
.
Do on board
Find weights that give exact results for polynomials up to degree 2 by requiring it to be exact for 
Derive Simpson’s rule with 1 pair of subintervals for range of integration [-a,a]
Assignment 7
Find values for weights 
, 
, and 
 by requiring the formula 
to be exact for f(x) = 1, f(x) = x, and f(x) = x
2
.
Composite Simpson’s rule:
G
e
n
e
r
a
l
i
z
e
d
 
t
h
i
s
 
r
e
s
u
l
t
 
f
o
r
 
1
 
p
a
i
r
 
o
f
s
u
b
i
n
t
e
r
v
a
l
s
 
o
n
 
[
-
a
,
 
a
]
 
t
o
 
n
 
p
a
i
r
s
 
o
f
s
u
b
i
n
t
e
r
v
a
l
s
 
o
n
 
[
a
,
 
b
]
,
 
w
h
e
r
e
 
w
e
 
d
o
n
o
t
e
t
h
e
 
 
w
i
d
t
h
 
o
f
 
s
u
b
i
n
t
e
r
v
a
l
s
 
a
s
 
h
.
n pairs of subintervals
MATLAB code for composite Simpson’s rule:
Layout of points when npairs = 4, npts = 2(npairs)+1 = 9
h = (b-a)/2(npairs)
i=0    1       2       3       4      5        6      7       8
   |-----|------|-------|-------|------|-------|------|-------| n=2npairs=8
   a   a+h
     
       b
Do on board
MatLab code for composite Simpson’s rule: 4 pairs of subintervals
i=0    1       2       3       4      5        6      7       8
   |-----|------|-------|-------|------|-------|------|-------| npoints = 9
   a   a+h
     
       b
function A = simprule(fh,a,b,npairs)
 
n=2*npairs; %number of sub intervals
 
h=(b-a)/n;
 
sum_even=0;
 
for i=2:2:n-2
  
sum_even=sum_even+fh(a+i*h);
 
end
 
sum_odd=0;
 
for i=1:2:n-1
  
sum_odd=sum_odd+fh(a+i*h);
 
end
 
A=h*(fh(a)+4*sum_odd+2*sum_even+fh(b))/3;
end
Download composite Simpson’s rule from the class web page. Write a script for the
problem “Approximate the integral
by composite trapezoid and Simpson’s rules with 3 and 5 points. Report the
absolute percent difference from the “exact” value of  -18.79829683678703 in
each case.
W
h
a
t
 
i
s
 
w
r
o
n
g
 
w
i
t
h
 
t
h
i
s
 
s
c
r
i
p
t
?
 
 
H
o
w
 
d
o
 
y
o
u
 
f
i
x
 
i
t
?
integrand=@(x) sin(10/x)*100/x; 
 
Why no ./ ?
exact= -18.79829683678703;
for npts=3:2:5
 
T=ctraprule(integrand,1,3,npts)
 
S=simprule(integrand,1,3,npts)
 
pdT=100*abs((T-exact)/exact);
 
pdS=100*abs((S-exact)/exact);
 
disp([npts, T, pdT, S, pdS]);
end
 
Download composite Simpson’s rule from the class web page. Write a script for the
problem “Approximate the integral
by composite trapezoid and Simpson’s rules with 3 and 5 points. Report the
absolute percent difference from the “exact” value of  -18.79829683678703 in
each case.
integrand=@(x) sin(10/x)*100/x;
exact= -18.79829683678703;
for npairs=1:2
 
ntps=2*npairs+1;
 
T=ctraprule(integrand,1,3,npts)
 
S=simprule(integrand,1,3,npairs)
 
pdT=100*abs((T-exact)/exact);
 
pdS=100*abs((S-exact)/exact);
 
disp([npts, T, pdT, S, pdS]);
end
 
Assignment 8: Approximate the integral
by composite trapezoid and Simpson’s rules with 3, 5, 7,and 9 points. Report the
absolute percent difference from the “exact” value of  -18.79829683678703 in
each case.
 
Hand in a copy of command window that shows your script for using
the 
composite trapezoid and Simpson’s rules 
and the results.
Let {x
0
, x
1
, …, x
n
} be n+1 points on [a, b] where integrand
evaluated, then the numerical integration formula
Will be exact for polynomials of degree at least n.
Derive weights by a system of n+1 linear equations
obtained by requiring the formula to be exact for
f(x) = 1, x, x
2
, …x
n
Trapezoid rule: (n = 1) exact for a line
 
In general, error proportional to |f’’(
)|
Simpson’s rule: (n = 2) exact for a cubic
 
In general, error proportional to |f
(4)
(
)|
 
How is this extra performance (cubic) possible?
Slide Note
Embed
Share

Most numerical integration formulas involve a weighted average of the integrand values. One approach is to approximate the integrand with a polynomial, integrate it, and derive the integration formula. This method is demonstrated with examples such as the composite trapezoid rule and Simpson's rule. By approximating the integrand with polynomials of different degrees, formulas for numerical integration can be derived and generalized.

  • Numerical Integration
  • Polynomial Approximation
  • Simpsons Rule
  • Integration Formulas
  • Mathematics

Uploaded on Feb 24, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Deriving numerical integration methods

  2. As was the case for the composite trapezoid rule, most numerical integration formulas have the form of a weighted average of values of the integrand. = a 0 k b n = ( ) ( ) f x dx f x k k One approach to deriving such formulas is to replace the integrand by a polynomial. Find the equation of the polynomial and integrate it. For example, trapezoid rule with 2 points. Do on board

  3. replace integrand with line (polynomial of degree = 1) 2 This example illustrates that any numerical integration formula that evaluates the integrand at n+1 point will be exact for a polynomial of degree n because we have enough information to find the polynomial and integrate it analytically. However, this approach to deriving numerical integration approximations is hard to generalize to polynomials of degree higher than 1.

  4. Derive the Simpsons rule approximation for numerical integration Approximate the integrand by a parabola (polynomial degree 2) Divide the range of integration into pairs of subintervals of equal width. Develop a system of equations for the weights in the average of integrand a b n = k = ( ) ( ) f x dx f x values by requiring the formula k k 0 to be exact for f(x) equal to 1, x, and x2. Do on board

  5. Derive Simpsons rule with 1 pair of subintervals for range of integration [-a,a] Find weights that give exact results for polynomials up to degree 2 by requiring it to be exact for

  6. Assignment 7 - Find values for weights , , and by requiring the formula to be exact for f(x) = 1, f(x) = x, and f(x) = x2.

  7. Composite Simpsons rule: Generalized this result for 1 pair of subintervals on [-a, a] to n pairs of subintervals on [a, b], where we donote the width of subintervals as h.

  8. n pairs of subintervals

  9. MATLAB code for composite Simpsons rule: Layout of points when npairs = 4, npts = 2(npairs)+1 = 9 h = (b-a)/2(npairs) i=0 1 2 3 4 5 6 7 8 |-----|------|-------|-------|------|-------|------|-------| n=2npairs=8 a a+h b Do on board

  10. MatLab code for composite Simpsons rule: 4 pairs of subintervals i=0 1 2 3 4 5 6 7 8 |-----|------|-------|-------|------|-------|------|-------| npoints = 9 a a+h b function A = simprule(fh,a,b,npairs) n=2*npairs; %number of sub intervals h=(b-a)/n; sum_even=0; for i=2:2:n-2 sum_even=sum_even+fh(a+i*h); end sum_odd=0; for i=1:2:n-1 sum_odd=sum_odd+fh(a+i*h); end A=h*(fh(a)+4*sum_odd+2*sum_even+fh(b))/3; end

  11. Download composite Simpsons rule from the class web page. Write a script for the problem Approximate the integral 10 sin( x 3 100 1 )dx x by composite trapezoid and Simpson s rules with 3 and 5 points. Report the absolute percent difference from the exact value of -18.79829683678703 in each case. What is wrong with this script? How do you fix it? integrand=@(x) sin(10/x)*100/x; exact= -18.79829683678703; for npts=3:2:5 T=ctraprule(integrand,1,3,npts) S=simprule(integrand,1,3,npts) pdT=100*abs((T-exact)/exact); pdS=100*abs((S-exact)/exact); disp([npts, T, pdT, S, pdS]); end Why no ./ ?

  12. Download composite Simpsons rule from the class web page. Write a script for the problem Approximate the integral 10 sin( x 3 100 1 )dx x by composite trapezoid and Simpson s rules with 3 and 5 points. Report the absolute percent difference from the exact value of -18.79829683678703 in each case. integrand=@(x) sin(10/x)*100/x; exact= -18.79829683678703; for npairs=1:2 ntps=2*npairs+1; T=ctraprule(integrand,1,3,npts) S=simprule(integrand,1,3,npairs) pdT=100*abs((T-exact)/exact); pdS=100*abs((S-exact)/exact); disp([npts, T, pdT, S, pdS]); end

  13. Assignment 8: Approximate the integral 3 100 10 1 sin( )dx x x by composite trapezoid and Simpson s rules with 3, 5, 7,and 9 points. Report the absolute percent difference from the exact value of -18.79829683678703 in each case.Hand in a copy of command window that shows your script for using the composite trapezoid and Simpson s rules and the results.

  14. Let {x0, x1, , xn} be n+1 points on [a, b] where integrand evaluated, then the numerical integration formula n f(x)dx a Will be exact for polynomials of degree at least n. Derive weights by a system of n+1 linear equations obtained by requiring the formula to be exact for f(x) = 1, x, x2, xn b = = k ( ) f x k k 0 Trapezoid rule: (n = 1) exact for a line In general, error proportional to |f ( )| Simpson s rule: (n = 2) exact for a cubic In general, error proportional to |f(4)( )| How is this extra performance (cubic) possible?

Related


More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#