Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#! /usr/bin/env python # -*- coding: utf-8 -*- Examples of several algorithm for numerical integration problems. See the `integrals.py <integrals.html>`_ file for more details.
- *Date:* Saturday 18 June 2016, 18:59:23. - *Author:* `Lilian Besson <https://bitbucket.org/lbesson/>`_ for the `CS101 course <http://perso.crans.org/besson/cs101/>`_ at `Mahindra Ecole Centrale <http://www.mahindraecolecentrale.edu.in/>`_, 2015. - *Licence:* `MIT Licence <http://lbesson.mit-license.org>`_, © Lilian Besson. """
# Do some quick tests (it should be in the 'tests.py' file):
# # %% Example 1
# print("With 15 left rectangles:", plot_riemann_left(f, 0, math.pi, # namef=r"$x \mapsto \cos(x)$",n=15, figname="riemannleft.png")) # print("With 15 right rectangles:", plot_riemann_right(f, 0, math.pi, # namef=r"$x \mapsto \cos(x)$",n=15, figname="riemannright.png")) # print("With 15 center rectangles:", plot_riemann_center(f, 0, math.pi, # namef=r"$x \mapsto \cos(x)$",n=15, figname="riemanncenter.png")) # print("With 3 trapezoides:", plot_trapez(f, 0, math.pi, # namef=r"$x \mapsto \cos(x)$",n=3, figname="trapezoides.png"))
# # %% Example 2 # f = lambda x: x**2 # print("Plotting and computing the integral of x**2 from 0 to 3.") # print("Formally, the value is about 9 (= 3**3 / 3).") # print("With 8 left rectangles:", plot_riemann_left(f, 0, 3, # namef="$x \mapsto x^2$", n=8, figname="riemannleft2.png")) # print("With 8 right rectangles:", plot_riemann_right(f, 0, 3, # namef="$x \mapsto x^2$", n=8, figname="riemannright2.png")) # print("With 8 center rectangles:", plot_riemann_center(f, 0, 3, # namef="$x \mapsto x^2$", n=8, figname="riemanncenter2.png")) # print("With 3 trapezoides:", plot_trapez(f, 0, 3, # namef="$x \mapsto x^2$", n=3, figname="trapezoides2.png"))
# %% Example 3 with Monte-Carlo
""" f1(x) = x"""
# For this particular example, its easy:
# plot_montecarlo(f, xmin, xmax, 1500, ymin, ymax, namef=r"$x \mapsto x$", figname="montecarlo.png")
# %% Example 4 with Monte-Carlo
""" f1(x) = x"""
# For this particular example, its easy:
# plot_montecarlo(f2, xmin, xmax, ymin, ymax, 1500, namef=r"$x \mapsto x^3$", figname="montecarlo2.png")
# %% Example 5 with Monte-Carlo
""" f3(x) = x"""
# For this particular example, its easy:
# plot_montecarlo(f3, xmin, xmax, ymin, ymax, 1500, namef=r"$x \mapsto 1/(1+\sinh(2x)\log(x)^2)$", figname="montecarlo3.png")
# plot_montecarlo(f3, xmin, xmax, ymin, ymax, 10000, namef=r"$x \mapsto 1/(1+\sinh(2x)\log(x)^2)$", figname="montecarlo4.png")
# End of tests.py |