• Home
  • About
    • C-H Kim's blog photo

      C-H Kim's blog

      Anyone is welcome who loving C / C++, Python, java... ect.

    • Learn More
    • Email
    • LinkedIn
    • Github
    • StackOverflow
    • Steam
  • Posts
    • All Posts
    • All Tags
  • Projects

Integration

30 Nov 2019

Reading time ~1 minute

Gauss Quadrature

this is numpy-friendly code
you need to have Closed-Form expression

How to use

example for integrating f(x) = sin(x^2)

import numpy as np
import Gauss_Quadrature as gq


def f(x):
    return np.sin(x**2)

x1 = np.arange(0, 10, 0.01)

#integrated value list y
y1 = gq.Quadrature(f, x1)

Simpson’s Rule

this is numpy-friendly code
you need to have values of function and x values with regular interval(no matter odd numbered or even numbered)
A number of samples will be decreased by more than half

How to use

example for integrating y1(note Gauss Quadrature code part)

import Simpson_Rule as sim

#integrate again!
y2, x2 = sim.Integration(y1, x1)

the last value of y2 is same as it’s second value from behind

  • Gauss Quadrature Code Link

  • Simpson’s Rule Code Link



Python Share Tweet