function module¶
Mathematical equations.
- Date
2019-11-04
-
cosine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False)[source]¶ A cosine wave is said to be sinusoidal, because, \(\cos(x) = \sin(x + \pi/2)\), which is also a sine wave with a phase-shift of π/2 radians. Because of this head start, it is often said that the cosine function leads the sine function or the sine lags the cosine.
- Parameters
A (float or int) – amplitude
k (float or int) – (angular) wave number
f (float or int) – ordinary frequency
phi (float or int) – phase
D (float or int) – non-zero center amplitude
degree (bool) – boolean to switch between radians and degree. If False phi is interpreted in radians and if True then phi is interpreted in degrees.
- Results
sine wave function of spatial variable x and optional time t
See also
-
epitrochoid(R, r, d)[source]¶ Epitrochoid
A point is attached with a distance d from the center of a circle of radius r. The circle is rolling around the outside of a fixed circle of radius R.
- Parameters
R (float) – radius of the fixed interior circle
r – radius of the rolling circle outside of the fixed circle
d (float) – distance from the center of the exterior circle
- Typre r
float
- Results
functions for x of theta and y of theta
- Return type
tuple
\[\begin{split}x(\theta) = (R + r)\cos\theta - d\cos\left(\frac{R+r}{r}\theta\right) \\ y(\theta) = (R + r)\sin\theta - d\sin\left(\frac{R+r}{r}\theta\right) \\ \theta = \left[0, 2\pi\right]\end{split}\]* * * * R * * * * * * * * * * r * * ** .... * * ** d * * * * * * * * * * * * * * * *
>>> x, y = epitrochoid(3, 1, 0.5)[:1] >>> x, y, theta_end = epitrochoid(3, 1, 0.5)
-
hypotrochoid(R, r, d)[source]¶ Hypotrochoid
A point is attached with a distance d from the center of a circle of radius r. The circle is rolling around the inside of a fixed circle of radius R.
- Parameters
R (float) – radius of the fixed exterior circle
r – radius of the rolling circle inside of the fixed circle
d (float) – distance from the center of the interior circle
- Typre r
float
- Results
functions for x of theta and y of theta
- Return type
tuple
\[\begin{split}x(\theta) = (R - r)\cos\theta + d\cos\left(\frac{R-r}{r}\theta\right) \\ y(\theta) = (R - r)\sin\theta - d\sin\left(\frac{R-r}{r}\theta\right) \\ \theta = \left[0, 2\pi\frac{\mathrm{lcm}(r, R)}{R}\right]\end{split}\]* * * * R * * * * * * * * * r ** * * .... * * * d * * * ** * * * * * * * * * * *
>>> x, y = hyotrochoid(20, 6, 6)[:1] >>> x, y, theta_end = hyotrochoid(20, 6, 6)
See also
-
sine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False)[source]¶ A sine wave or sinusoid is a mathematical curve that describes a smooth periodic oscillation.
- Parameters
A (float or int) – amplitude
k (float or int) – (angular) wave number
f (float or int) – ordinary frequency
phi (float or int) – phase
D (float or int) – non-zero center amplitude
degree (bool) – boolean to switch between radians and degree. If False phi is interpreted in radians and if True then phi is interpreted in degrees.
- Results
sine wave function of spatial variable x and optional time t
In general, the function is:
\[\begin{split}y(x,t) = A\sin(kx + 2\pi f t + \varphi) + D \\ y(x,t) = A\sin(kx + \omega t + \varphi) + D\end{split}\]where:
A, amplitude, the peak deviation of the function from zero.
f, ordinary frequency, the number of oscillations (cycles) that occur each second of time.
ω = 2πf, angular frequency, the rate of change of the function argument in units of radians per second. If ω < 0 the wave is moving to the right, if ω > 0 the wave is moving to the left.
φ, phase, specifies (in radians) where in its cycle the oscillation is at t = 0.
x, spatial variable that represents the position on the dimension on which the wave propagates.
k, characteristic parameter called wave number (or angular wave number), which represents the proportionality between the angular frequency ω and the linear speed (speed of propagation) ν.
D, non-zero center amplitude.
The wavenumber is related to the angular frequency by:
\[k={\omega \over v}={2\pi f \over v}={2\pi \over \lambda }\]where λ (lambda) is the wavelength, f is the frequency, and v is the linear speed.
See also
-
to_str(f, x=None, x_0=0, x_1=1, t=None, h=10, w=80, density=1, char_set='line')[source]¶ Represent functions as string frame with a specific character set. which are normed to the range of [0, 1] to
- Parameters
f (function or list) – function or list of functions normed to the range of [0, 1]
h (int) – number of chars in vertical direction
w (int) – number of chars in horizontal direction
char_set (str) – either “braille” or “block”. “braille” uses Unicode Characters in the Braille Patterns Block (fisrt index U+2800, last index U+28FF [CUDB]) and the “block” uses part of the Unicode Characters in the Block Elements Block (fisrt index U+2580, last index U+259F [CUDB]). Alias for braille is line and alias for block is histogram
- Usage:
case dependent arguments
1 quasi line plot (braille characters) f = lambda function (lambda x, t=0: …) x_1 = max x value x_0 = min x value t = time (animation)
2 histogram (block characters) f = lambda function (lambda x, t=0: …) x_1 = max x value x_0 = min x value t = time (animation) chart=”histogram”
general arguments w = window width in number of chars density = number of data point per pixel (for line chart higher density makes thicker lines) chart = either “line” or “histogram”
Braille Patterns Block
Dots or pixels per character in vertical direction: 6
Dots or pixels per character in horizontal direction: 2
First dot (bottom left) is the zero (0) position of the function. So, a function value of zero does not mean to have zero dots but one. Example of 3 columns and 3 rows (upside down view of ‘normal’ braille/drawille position)
| ^ y axis | | | ,_____,,_____,,_____, 7 + | * *|| * *|| * *| 6 + | * *|| * *|| * *| 5 + | * *|| * *|| * *| 4 + | * *|| * *|| * *| | ;=====;;=====;;=====; 3 + | * *|| * *|| * *| 2 + | * *|| * *|| * *| 1 + | * *|| * *|| * *| 0 + - | * *|| * *|| * *| ---> x axis | ;=====;;=====;;=====; -1 + | * *|| * *|| * *| -2 + | * *|| * *|| * *| -3 + | * *|| * *|| * *| -4 + | * *|| * *|| * *| | ````````````````````` | | `-----+--+---+--+---+--+------------- -2 -1 0 1 2 3Block Elements Block
Dots or pixels per character in vertical direction: 8
Dots or pixels per character in horizontal direction: 1
Example of 3 columns and 3 rows
| ^ y axis | | | ,_____,,_____,,_____, 15 + | --- || --- || --- | 14 + | --- || --- || --- | 13 + | --- || --- || --- | 12 + | --- || --- || --- | 11 + | --- || --- || --- | 10 + | --- || --- || --- | 9 + | --- || --- || --- | 8 + | --- || --- || --- | | ;=====;;=====;;=====; 7 + | --- || --- || --- | 6 + | --- || --- || --- | 5 + | --- || --- || --- | 4 + | --- || --- || --- | 3 + | --- || --- || --- | 2 + | --- || --- || --- | 1 + | --- || --- || --- | 0 + - | --- || --- || --- | ---> x axis | ;=====;;=====;;=====; -1 + | --- || --- || --- | -2 + | --- || --- || --- | -3 + | --- || --- || --- | -4 + | --- || --- || --- | -5 + | --- || --- || --- | -6 + | --- || --- || --- | -7 + | --- || --- || --- | -8 + | --- || --- || --- | | ````````````````````` | | `------+------+------+--------------- -1 0 1References
See also
-
transformation(f, scale_vertical=1, scale_horizontal=1, shift_horizontal=0, shift_vertical=0)[source]¶ Transform functions.
- Parameters
f (function or list) – function or list of functions
scale_vertical – “a” scale factor in vertical direction (default = 1)
scale_horizontal – “b” scale factor in horizontal direction (default = 1)
shift_horizontal – “c” shift factor in horizontal direction (default = 0)
shift_vertical – “d” shift factor in vertical direction (default = 0)
- Returns
transformed function or list of transformed functions
- Return type
function or list
\[y = a \, f(b\,(x-c)) + d\]