Skip to content

MANE 3351

Lecture 16

Classroom Management

Agenda

  • Gaussian Quadrature
  • Homework 4 (due 10/29/2025)
  • Homework 5 (due November 3 - no late work)
  • Lab 6 due before 9:30 AM
  • Lab 7 after lecture (due 11/3/2025)

Resources

Handouts

Calendar

Week Monday Lecture Wednesday Lecture
9 10/27: Gaussian Quadrature 10/29: Numerical Differentiation (not on Test 2)
10 11/3: Linear Algebra 11/5: Test 2 (Root Finding and Numerical Integration)

Lecture 16

Today's topic is Gaussian Quadrature

  • \(\int_{-1}^1f(x)dx\approx\sum_{i=1}^nw_if(x_i)+R_n\)
  • \(x_i\) is the abscissa is the \(i\)-th zero of \(P_n(x)\) (Legendre polynomial)
  • \(w_i\) is the weight associate with \(x_i\)
  • \(R_n=\frac{2^{2n+1}(n!)^4}{(2n+1)[(2n)!]^3}f^{(2n)}(\xi)\)
  • Abscissas and weights are commonly tabled 1

Python Code, part 1

# Part 1, original formula in range (-1,1)
#
import math
import numpy as np
def f(z):
    return (math.exp(-0.5*z**2)/((2.0*math.pi)**0.5))
#
# 2 point Gaussian Quadrature
x2=[-0.577350269189626,0.577350269189626]
w2=[1.0,1.0]
#
i2=0.0
for i in range(0,len(x2)):
    i2=i2+w2[i]*f(x2[i])
print("the area using 2-point gaussian quadrature is {}".format(i2))
#
# 5 point Gaussian Quadrature
x5=[0.0, -0.538469310105683,0.538469310105683,-0.906179845938664,0.906179845938664]
w5=[0.568888888888889,0.478628670499366,0.478628670499366,0.236926885056189,0.236926885056189]
i5=0.0
for i in range(0,len(x5)):
    i5=i5+w5[i]*f(x5[i])
print("the area using 5-point gaussain quadrature is {}".format(i5))

Gauss' Formula, Arbitrary Interval

  • \(\int_{a}^bf(y)dy\approx\frac{b-a}{2}\sum_{i=1}^nw_if(y_i)+R_n\)
  • \(y_i=\left(\frac{b-a}{2}\right)x_i+\left(\frac{b+a}{2}\right)\)
  • \(R_n=\frac{(b-a)^{2n+1}(n!)^4}{(2n+1)[(2n)!]^3}f^{(2n)}(\xi)\)
  • Note that \(x_i\) and \(w_i\) are the points and weights of Gaussian quadrature

Python Code, part 2

# Part 2
#
print("Gaussian Quadrature, arbitrary interval")
a=-5.0
b=0.0
#
# redo 2 point gaussian
i2=0.0
for i in range(0,len(x2)):
    y=((b-a)/2.0)*x2[i]+(b+a)/2.0
    i2=i2+w2[i]*f(y)
i2=((b-a)/2.0)*i2
print("the area using 2-point gaussian quadrature is {}".format(i2))
#
# redoc 5 point gaussian
i5=0.0
for i in range(0,len(x5)):
    y=((b-a)/2.0)*x5[i]+(b+a)/2.0
    i5=i5+w5[i]*f(y)
i5=((b-a)/2.0)*i5
print("the area using 5-point gaussian quadrature is {}".format(i5))

ChatGPT program

  • ChatGPT can be a useful tool for developing Python code.
  • It should not replace your knowledge and expertise
  • ChatGPT can be wrong


  1. Abramowitz, M., and Stegun, I. (1972), Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables