API Documentation¶
Distributions¶
-
mathtoolspy.distribution.normal_distribution.
density_normal_dist
(x)[source]¶ Density function for normal distribution @param x: float value @return value of normal density function
Interpolation¶
-
mathtoolspy.interpolation.linear.
interpolation_linear
(x, x1, x2, y1, y2)[source]¶ Linear interpolation returns (y2 - y1) / (x2 - x1) * (x - x1) + y1
-
class
mathtoolspy.interpolation.spline.
base_interpolation
(x_list=[], y_list=[])[source]¶ Bases:
object
Basic class to interpolate given data.
-
class
mathtoolspy.interpolation.spline.
spline
(x_list=[], y_list=[], boundary_condition=None)[source]¶ Bases:
mathtoolspy.interpolation.spline.base_interpolation
interpolates the data with cubic splines.
Parameters: - x_list – data
- y_list – data
- boundary_condition – Either a tuple (l, r) of values for the slope or None. If the argument is not specified then None will be taken as boundary conditions, which leads to the so called not-a-knot method for splines. Not-a-knot will determine the boundary conditions by also requiring that the third derivatives of the two most left and the two most right interpolation polynomials agree. The boundary condition (0,0) will lead to the so called natural spline
-
mathtoolspy.interpolation.bilinear.
interpolation_bilinear
(x, y, x1, x2, y1, y2, z11, z21, z22, z12)[source]¶ The points (x_i, y_i) and values z_ij are connected as follows: Starting from lower left going in mathematically positive direction, i.e. counter clockwise. Therefore: (x1,y1,z11), (x2,y1,z21), (x2,y2,z22), (x1,y2,z12).
Integration¶
-
class
mathtoolspy.integration.gauss_kronrod_integrator.
GaussKronrodIntegrator
(max_number_of_iterations=255, initial_order=3, min_number_of_iterations=7, abs_tolerance=1e-10, rel_tolerance=0.0001, check_abs_tolerance=True, check_rel_tolerance=False)[source]¶ Bases:
object
-
class
mathtoolspy.integration.gauss_kronrod_integrator.
GaussKronrodConstants
[source]¶ Bases:
object
Constants for Gauss Kronrod Integrator
-
min_max_iter
= 7¶
-
gaussKronrodPattersonRule
= [3, 7, 15, 31, 63, 127, 255]¶
-
FL
= [1, 2, 4, 8, 11, 13, 0]¶
-
FH
= [1, 3, 7, 15, 16, 16, -1]¶
-
KL
= [0, 0, 0, 0, 0, 2, 4, 8, 4, 8, 11]¶
-
KH
= [0, 1, 3, 7, 15, 2, 5, 16, 4, 8, 16]¶
-
KX
= [0, 1, 2, 3, 4, 5, 8, 11]¶
-
coefficients
= [-0.1111111111111111, 0.22540333075851662, 0.5555555555555556, 0.006472094214029698, -0.009289687909444337, 0.039508731291979717, 0.10465622602646726, 0.5657562506531975, 0.40139741477596225, 5.223046896961622e-05, 0.0001712103096175, -0.0007248300161538929, -7.017801099209042e-05, 0.0061680367872449775, 0.01700171962994026, 0.111540767127743, 0.09292719531512454, 0.3788970532627736, 0.1715119091363914, 0.7766133135710331, 0.2191568584015875, 6.82166534792e-09, 1.2667409859336e-07, 5.9565976367837166e-06, 1.392330106826e-08, -6.629407564902392e-05, -7.04395804282302e-07, -3.4518205339241e-08, -8.14486910996e-09, 0.0009018750323324024, 0.0025447807915618746, 0.018468850446259892, 0.01644604985438781, 0.07034514257025995, 0.03595710330712932, 0.16327406183113127, 0.05697950949412336, 0.29750379350847295, 0.07687962049900353, 0.4686802563556244, 0.09362710998126447, 0.6688646067420232, 0.1056698935802348, 0.8875110568668134, 0.11195687302095346, 3.71583e-16, 2.1237877e-13, 1.0522629388435e-09, 1.748029e-15, 3.47571898301716e-07, 9.0312761725e-12, 1.2558916e-14, 5.4591e-16, -7.233839550869196e-06, -1.69699579757977e-08, -8.54363907155e-11, -1.228130093e-12, -4.62334825e-14, -4.2244055e-15, -8.8501e-16, -4.0904e-16, 0.00012711187964238805, 0.00036322148184553065, 0.0027937406277780408, 0.0025790497946856883, 0.01131524245257052, 0.006115506822117246, 0.027817125251418204, 0.010498246909621322, 0.05365714162659709, 0.015406750466559498, 0.0896288430429957, 0.02059423391591271, 0.13609206180630953, 0.025869679327214748, 0.19305946804978238, 0.031073551111687966, 0.26024395564730524, 0.03606443278078257, 0.3370903399752194, 0.04071551011694432, 0.42280428994795416, 0.0449145316536322, 0.516381973054159, 0.0485643304066732, 0.6166406758012697, 0.051583253952048456, 0.7222501779781757, 0.05390549933526606, 0.8317647484477926, 0.05548140435655936, 0.9436556869534072, 0.0562776998312543, 1.041098e-16, 2.49472054598e-11, 5.5e-21, 2.90412475995385e-08, 3.67282126e-14, 5.568e-19, -8.71176477376972e-07, -8.147324267441e-10, -8.830920337e-13, -1.8018239e-15, -7.0528e-18, -5.06e-20, 1.7569645108401418e-05, 5.053609520786252e-05, 0.0004012003280893168, 0.00037774664632698465, 0.0016833646815926076, 0.0009383698485423815, 0.0042758953015928115, 0.00168114286542147, 0.008504278821893868, 0.0025687649437940202, 0.014628500401479628, 0.0035728927835172995, 0.022858485360294285, 0.0046710503721143215, 0.03336214844158343, 0.00584344987583564, 0.04626999357423886, 0.007072489995433555, 0.061679602220407116, 0.008342838753968157, 0.07965997452998758, 0.009641177729702537, 0.10025510022305996, 0.010955733387837901, 0.12348658551529473, 0.01227583056008277, 0.14935550523164973, 0.013591571009765546, 0.1778437456350196, 0.014893641664815181, 0.20891506620015163, 0.01617321872957772, 0.24251603361948637, 0.017421930159464173, 0.2785769146299011, 0.01863184825613879, 0.31701256890892077, 0.019795495048097498, 0.3577233574902405, 0.020905851445812022, 0.40059606975775713, 0.021956366305317825, 0.44550486736806744, 0.02294096422938775, 0.4923122424662834, 0.02385405210603854, 0.5408699880101676, 0.024690524744487678, 0.5910201787701114, 0.025445769965464767, 0.6425961621684678, 0.0261156733767061, 0.695423558443286, 0.02669662292745036, 0.7493212696965168, 0.027185513229624793, 0.8041024972888998, 0.027579749566481872, 0.8595757668474399, 0.027877251476613702, 0.9155459599162891, 0.028076455793817248, 0.9718153510502543, 0.0281763190330166, 3.326e-19, 1.14094770478e-12, 2.952436056970351e-09, 5.1608328e-16, -1.1017721965059732e-07, -5.8656987416475e-11, -2.3340340645e-14, -1.24895e-17, 2.4036202515353808e-06, 6.937936432410826e-06, 5.600379294562424e-05, 5.327529366978061e-05, 0.00023950907556795267, 0.00013575491094922873, 0.000619661974976418, 0.0002492124004829973, 0.0012543855319048854, 0.00038974528447328227, 0.0021946455040427254, 0.0005542953149303748, 0.003485854085109726, 0.0007402828042445033, 0.005168497199379, 0.0009453615168585254, 0.007278655717211385, 0.0011674841174299593, 0.00984862959922984, 0.0014049079956551446, 0.012907472045965932, 0.0016561127281544527, 0.01648134242136727, 0.0019197129710138725, 0.020593718329137315, 0.002194406925363839, 0.02526554024759733, 0.002478958226657568, 0.030515340497540767, 0.002772195764593451, 0.03635937843018787, 0.0030730184347025785, 0.04281178389013904, 0.0033803979910869203, 0.04988470247870512, 0.003693377917025651, 0.05758843480891694, 0.0040110687240750235, 0.06593156384227421, 0.004332640968092983, 0.07492106709292434, 0.004657317299756855, 0.08456241284423496, 0.004984364564765539, 0.09485964118673841, 0.005313086605187057, 0.10581543166444098, 0.005642818101384444, 0.1174311597526581, 0.005972919565508166, 0.1297069444518861, 0.006302773449085758, 0.14264168911376784, 0.006631781242901888, 0.1562331173272914, 0.006959361409390423, 0.1704778053625986, 0.007284947980553807, 0.1853712123448626, 0.007607989665719056, 0.2009077090391586, 0.007927949334294849, 0.217080605881717, 0.008244303763032867, 0.23388218069623992, 0.00855654356130769, 0.2513037063830634, 0.008864173209482495, 0.2693354787578187, 0.00916671116356079, 0.28796684463774797, 0.009463689993830066, 0.3071862302208853, 0.009754656536317411, 0.3269811697695815, 0.01003917204405684, 0.3473383345899825, 0.010316812330947622, 0.3682435622888058, 0.010587167904885198, 0.3896818862848136, 0.010849844089337314, 0.41163756555233744, 0.011104461134006927, 0.43409411457634556, 0.011350654315980596, 0.4570343335016885, 0.011588074033043953, 0.48044033846254297, 0.011816385890830236, 0.5042935920812386, 0.012035270785279563, 0.5285749341283411, 0.012244424981611986, 0.5532646123379715, 0.012443560190714036, 0.5783423133738367, 0.01263240364354208, 0.6037871939423841, 0.012810698163877362, 0.6295779120499218, 0.0129782022395374, 0.655692658400562, 0.013134690091960152, 0.6821091879315233, 0.01327995174393053, 0.7088048514817533, 0.013413793085110098, 0.7357566275890732, 0.013536035934956213, 0.7629411544101703, 0.013646518102571292, 0.7903347617568188, 0.013745093443001897, 0.8179135032407479, 0.013831631909506429, 0.8456531885186219, 0.013906019601325462, 0.873529415627698, 0.013968158806516938, 0.9015176034018808, 0.014017968039456609, 0.9295930239571448, 0.014055382072649964, 0.9577308352346364, 0.014080351962553661, 0.9859061135892175, 0.014092845069160408]¶
-
-
class
mathtoolspy.integration.gauss_legendre_integrator.
GaussLegendreIntegrator
(steps=100)[source]¶ Bases:
object
Gauss Legendre integrator, which uses the Gauss Legendre quadratures
-
class
mathtoolspy.integration.gauss_legendre_integrator.
GaussLegendreQuadratures
[source]¶ Bases:
object
-
class
mathtoolspy.integration.gauss_lobatto_integrator.
GaussLobattoStep
(function, alpha, beta, Is, max_number_of_iterations)[source]¶ Bases:
object
-
class
mathtoolspy.integration.gauss_lobatto_integrator.
GaussLobattoIntegrator
(max_number_of_iterations=255, abs_tolerance=1e-10)[source]¶ Bases:
object
Solver¶
-
mathtoolspy.solver.analytic_solver.
roots_of_cubic_polynom
(a1, a2, a3)[source]¶ Finds the roots of a 3 dim polymon of the form x^3 + a1 * x^2 + a2 * x + a3. The roots are returned as complex numbers.
-
mathtoolspy.solver.minimize_algorithm_1dim_brent.
shift
(a, b, c)[source]¶ The shift function returns the values as tuple.
-
mathtoolspy.solver.minimize_algorithm_1dim_brent.
minimize_algorithm_1dim_brent
(fct, _a, _b, _c, tolerance=1e-13)[source]¶ Finds the minimum of the given function f. The arguments are the given function f, and given a bracketing triplet of abscissas A, B, C (such that B is between A and C, and f(B) is less than both f(A) and f(C)) and the Tolerance. This routine isolates the minimum to a fractional precision of about tol using Brent’s method. The abscissa of of the minimum is returned as xmin, and the minimum value is returned as brent, the returned function value.
-
mathtoolspy.solver.minimize_algorithm_1dim_golden.
minimize_algorithm_1dim_golden
(function, a, b, c, tolerance=1e-13)[source]¶ Given a function f, and given a bracketing triplet of abscissas ax, bx, cx (such that bx is between ax and cx, and f(bx) is less than both f(ax) and f(cx)), this routine performs a golden section search for the minimum, isolating it to a fractional precision of about tol. The abscissa of the minimum is returned as xmin, and the minimum function value is returned as Golden, the returned function value. See Press, et al. (1992) “Numerical recipes in C”, 2nd ed., p.401.
-
class
mathtoolspy.solver.minimize_algorithm_ndim_powell.
MinimizeAlgorithmNDimPowell
[source]¶ Bases:
object
The minimazation with the Powell algorithm. Press, et al., ‘Numerical Recipes in C’, 2nd ed, Powell (p.412).
Minimization of a function func of n variables. Input consists of an initial starting point p[0..n-1]; an inital matrix xi[0..n-1,0..n-1], whose columns contain the initial set of directions (usually the n unit vectors); and ftol, the fractional tolerance in the function value such that failure to decrease by more than this amount on one iteration signals doneness. On output, p is set to best point found, xi is the then-current direction set, fret is the returned function value at p. The routine linmin is used. * Initial matrix xi[0..n-1,0..n-1], whose columns contain the initial set of directions (usually the n unit vectors). On output xi is the then-current direction set. * Initial starting point p[0..n-1]. On output p is set to best point found.
-
TINY
= 1e-25¶
-
TOL
= 0.0002¶
-
-
mathtoolspy.solver.minimum_bracketing.
GLIMIT
= 100.0¶ Used to prevent any possible division by zero.
-
mathtoolspy.solver.minimum_bracketing.
minimum_bracketing
(fct, initial_value=0.0, natural_length=1.0000000000001)[source]¶ Given a function func, and given distinct inital points ax and bx, this routine searches in the downhill direction (defined by the function as evaluated at the initial points) and returns new points at ax, bx, cx that bracket a minimum of the function. Also returned are the function values at the three points. See Press, et al. (1992) “Numerical recipes in C”, 2nd ed., p.400.
-
mathtoolspy.solver.minimum_bracketing.
simple_bracketing
(func, a, b, precision=1e-20)[source]¶ find root by simple_bracketing an interval
Parameters: - func (callable) – function to find root
- a (float) – lower interval boundary
- b (float) – upper interval boundary
- precision (float) – max accepted error
Return type: tuple
Returns: (a, m, b)
of last recursion step withm = a + (b-a) *.5
-
class
mathtoolspy.solver.optimizer.
DeviationFct
(fct, rescale=None, max_number_of_function_calls=5000)[source]¶ Bases:
object
Utilities¶
The MathFct contains some mathematically method, which are not supported by the Python lib.
-
mathtoolspy.utils.math_fcts.
sign
(x)[source]¶ Returns the sign of the double number x. -1 if x < 0; 1 if x > 0 and 0 if x == 0
-
mathtoolspy.utils.math_fcts.
prod
(factors)[source]¶ The product of the given factors (iterable) :param factors: :return:
-
mathtoolspy.utils.math_fcts.
get_grid
(start, end, nsteps=100)[source]¶ Generates a equal distanced list of float values with nsteps+1 values, begining start and ending with end.
Parameters: start – the start value of the generated list. :type float
Parameters: end – the end value of the generated list. :type float
Parameters: nsteps – optional the number of steps (default=100), i.e. the generated list contains nstep+1 values. :type int
-
mathtoolspy.utils.mathconst.
DOUBLE_TOL
= 1e-13¶ PI
-
mathtoolspy.utils.mathconst.
PI
= 3.141592653589793¶ The factor $sqrt{2}$.
-
mathtoolspy.utils.mathconst.
SQRT_OF_TWO
= 1.414213562373095¶ $sqrt{Pi}$.
Type: The factor
-
mathtoolspy.utils.mathconst.
SQRT_OF_PI
= 1.772453850905516¶ $sqrt{2*Pi}$.
Type: The factor
-
mathtoolspy.utils.mathconst.
SQRT_OF_TWO_PI
= 2.506628274631¶ $1/sqrt{2Pi}$.
Type: The prefactor of the normal density
-
mathtoolspy.utils.mathconst.
ONE_OVER_SQRT_OF_TWO_PI
= 0.398942280401433¶ The factor $1/{2Pi}$.
-
mathtoolspy.utils.mathconst.
ONE_OVER_TWO_PI
= 0.15915494309189532¶ The golden ratio.
-
mathtoolspy.utils.mathconst.
GOLD
= 0.61803399¶ One minus GOLD
-
mathtoolspy.utils.mathconst.
ONE_MINUS_GOLD
= 0.38196601¶ One over GOLD
-
class
mathtoolspy.utils.surface.
Surface
(xaxis, yaxis, values)[source]¶ Bases:
object
A matrix with interpolation and extrapolation.
The values has to be a float matrix implementing the method get_item(i, j). @params xaxis: list of float values. @params yaxis: list of float values. @params values: some object implementing a get_item(i, j) method or nested list.