From 92375a91e6c3511a9a95a3f2ec03e8acab98c6ef Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Mon, 4 Nov 2019 15:40:58 +0100 Subject: [PATCH] add transformation function --- docs/build/html/_modules/function.html | 46 ++++++++++++++++++++++++- docs/build/html/function.html | 31 ++++++++++++++++- docs/build/html/genindex.html | 2 ++ docs/build/html/objects.inv | Bin 875 -> 886 bytes docs/build/html/searchindex.js | 2 +- pylib/function.py | 46 ++++++++++++++++++++++++- 6 files changed, 123 insertions(+), 4 deletions(-) diff --git a/docs/build/html/_modules/function.html b/docs/build/html/_modules/function.html index 36a7988..c9f43dd 100644 --- a/docs/build/html/_modules/function.html +++ b/docs/build/html/_modules/function.html @@ -37,7 +37,7 @@ # -*- coding: utf-8 -*- """Mathematical equations. -:Date: 2019-11-02 +:Date: 2019-11-04 .. module:: function :platform: *nix, Windows @@ -48,6 +48,50 @@ import math from pylib.mathematics import lcm +
[docs]def transformation(f, scale_vertical=1, scale_horizontal=1, + shift_horizontal=0, shift_vertical=0): + r"""Transform functions. + + :param f: function or list of functions + :type f: function or list + :param scale_vertical: "a" scale factor in vertical direction (default + = 1) + :type height: float + :param scale_horizontal: "b" scale factor in horizontal direction + (default = 1) + :type height: float + :param shift_horizontal: "c" shift factor in horizontal direction + (default = 0) + :type height: float + :param shift_vertical: "d" shift factor in vertical direction (default + = 0) + :type height: float + + :returns: transformed function or list of transformed functions + :rtype: function or list + + .. math:: + y = a \, f(b\,(x-c)) + d + """ + # shorter variables + a = scale_vertical + b = scale_horizontal + c = shift_horizontal + d = shift_vertical + + # check if f is a function than put it in a list and return only + # the function, not the one element list + if callable(f): + return function_transformation( + [f], scale_vertical=a, scale_horizontal=b, shift_horizontal=c, shift_vertical=d)[0] + + # otherwise assume list of functions + if not f: # if f is empty. End of the recursive fucntion + return [] + return [lambda x, t: a*f[0](b*(x-c), t)+d] +\ + function_transformation( + f[1:], scale_vertical=a, scale_horizontal=b, shift_horizontal=c, shift_vertical=d)
+
[docs]def sine_wave(A=1, k=1, f=1, phi=0, D=0, degree=False): r"""A sine wave or sinusoid is a mathematical curve that describes a smooth periodic oscillation. diff --git a/docs/build/html/function.html b/docs/build/html/function.html index 3c52adc..047c986 100644 --- a/docs/build/html/function.html +++ b/docs/build/html/function.html @@ -37,7 +37,7 @@

Mathematical equations.

Date
-

2019-11-02

+

2019-11-04

@@ -232,6 +232,35 @@ linear speed.

+
+
+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\]
+
+ diff --git a/docs/build/html/genindex.html b/docs/build/html/genindex.html index 26f2787..f4cb7ea 100644 --- a/docs/build/html/genindex.html +++ b/docs/build/html/genindex.html @@ -319,6 +319,8 @@
  • time_of_day (module), [1]
  • transform() (in module time_of_day) +
  • +
  • transformation() (in module function)