kitpylib.PyMath package#
Module contents#
Submodules#
kitpylib.PyMath.findroot module#
- kitpylib.PyMath.findroot.bisection(f, a, b, e, showtimes=False)#
BISECTION#
A function to find roots of f(x)=0 by bisection method. f(a) and f(b) cannot have the same signs.
Parameters#
- ffunc
f must be continuous. Python function returning a number.
- afloat
Start of the bracketing interval [a,b].
- bfloat
End of the bracketing interval [a,b].
- efloat
Accuracy
- showtimesbool. The default is False.
Show how many times the calculator use to find the root.
Returns#
- iterations:
Returns if showtimes is True.
- rootfloat
Root of f between a and b.
Examples#
Precise value:
>>> f = lambda x: x**2-1 >>> root = bisection(f, 0, 2, 0.01) >>> root 1.0
Errors:
>>> root = bisection(f, -2, 2, 0.01) ValueError: Incorrect input!
Approximate value:
>>> g = lambda x: -x**3-3*x+5 >>> root = bisection(g, 1, 2, 0.01) >>> root 1.1484375
showtimes is True:
>>> bisection(g, 1, 2, 0.01, showtimes=True) Finding root in 7 times. 1.1484375
kitpylib.PyMath.mathfuncs module#
kitpylib.PyMath.spf1d module#
- class kitpylib.PyMath.spf1d.PC(f, px1, py1)#
Bases:
object== This is a class of the calculation of pedal curves.
Parameters#
f(function), px1, py1(x, y of the point)
Returns#
a, b: x, y of the function
x, y: x, y of pedal curves
Example#
>>> f = lambda x: x**2-1 >>> a = PC(f, 0, 0) >>> a.a array([-5. , -4.9989999, -4.9979998, ..., 4.9979998, 4.9989999, 5. ])
- kitpylib.PyMath.spf1d.diff1st(f0, x, h=0.01)#
This is the 1st order derivative of a function.
\[f'(x)=(f(x + h) - f(x - h))/(2*h)\]
- kitpylib.PyMath.spf1d.diff2nd(f0, x, h=0.01)#
This is the 2nd order derivative of a function.
\[f''(x)=(f(x-h)-2*f(x)+f(x+h))/(h*h)\]
kitpylib.PyMath.spf2d module#
A module for 2d special functions.
- kitpylib.PyMath.spf2d.gaus2d(x)#
The 2d Gaussian Function.
- kitpylib.PyMath.spf2d.ramp2d(x)#
The 2d ramp function.
- kitpylib.PyMath.spf2d.rect2d(x)#
The 2d rectangle function.
- kitpylib.PyMath.spf2d.sign2d(x)#
The 2d sign function.
- kitpylib.PyMath.spf2d.sinc2d(x)#
The 2d sinc function.
- kitpylib.PyMath.spf2d.step2d(x)#
The 2d step function.
- kitpylib.PyMath.spf2d.tri2d(x)#
The 2d triangle function.
kitpylib.PyMath.spf3d module#
A module for 3d special functions.
- kitpylib.PyMath.spf3d.gaus3d(x, y)#
The 3d Gaussian Function.
- kitpylib.PyMath.spf3d.ramp3d(x, y)#
The 3d ramp function.
- kitpylib.PyMath.spf3d.rect3d(x, y)#
The 3d rectangle function.
- kitpylib.PyMath.spf3d.sign3d(x, y)#
The 3d sign function.
- kitpylib.PyMath.spf3d.sinc3d(x, y)#
The 3d sinc function.
- kitpylib.PyMath.spf3d.step3d(x, y)#
The 3d step function.
- kitpylib.PyMath.spf3d.tri3d(x, y)#
The 3d triangle function.