Skip to main content

Intuitive package to easily work with mathematical functions

Project description

skipi

skipi is a library to easily define mathematical functions and apply various transforms on it.

A function always consists of a domain and a map. Usually the domain is ommited since it's clear for the human what the domain is, however, not for the computer.

This library aims to combine the domain and the map into one Function object and offer multiple convenient operations on it.

Examples

Algebraic operations

Supported features are: Addition, Subtraction, Multiplication, Division, Exponentiation, Composition

import numpy as np
from skipi.function import Function

f = Function(np.linspace(0, 10, 100), lambda x: 2+x)
g = Function(f.get_domain(), lambda x: np.sin(x))
h1, h2, h3, h4, h5, h6 = f+g, f-g, f*g, g/f, f.composeWith(g), f**g

Plotting

A function is plotted using matplotlib calling plot(). If you want to plot multiple functions into one graph, simply use

g.plot()  # does not draw the graph yet
f.plot(show=True) # draws it

Remeshing

If you want to re-mesh a function on a different domain/grid, you can use remesh or vremesh. The method remesh assigns a new mesh, independent of the previous one.

f = Function(np.linspace(0, 10, 10), lambda x: np.sin(x))
f.remesh(np.linspace(0, 20, 1000))

However, if you want to restrict the domain, you can use vremesh which has a similar syntax as slice except that instead of indices we use values and it allows multiple slicing:

f = Function(np.linspace(0, 10, 1000), lambda x: np.sin(x))
f.vremesh((np.pi, 2*np.pi)) # domain is now restricted to [pi, 2pi]
f.vremesh((None, 2*np.pi)) # domain is now restricted to [0, 2pi]
f.vremesh((np.pi, None)) # domain is now restricted to [pi, 10]
f.vremesh((0.5, 1.5), (2.0, 2.5)) # domain is now restricted to [0.5, 1.5] union [2.0, 2.5]

Creating functions from data

If you don't have an analytical formulation of y = f(x), but rather have y_i and x_i values, then you can create a function by interpolation. By default, linear interpolation is used.

x_i = np.linspace(0, 10, 100)
y_i = np.sin(x_i)

f = Function.to_function(x_i, y_i)
print(f(0.1234)) # linearly interpolated, not sin(0.1234)!

Integration

Calculate the integral function of f(x) = 5x

import numpy as np
from skipi.function import Function, Integral

f = Function(np.linspace(0, 10, 100), lambda x: 5*x)
F = Integral.from_function(f) # Integral function
F.plot(show=True)

Fourier transform

Calculate the fourier transform (analytical fourier transform, not fft) of f(x) = exp(-x^2)

from skipi.fourier import FourierTransform, InverseFourierTransform

t_space, freq_space = np.linspace(-5, 5, 100), np.linspace(-10, 10, 100)
f = Function(t_space, lambda x: np.exp(-x**2))
F = FourierTransform.from_function(freq_space, f)
f2 = InverseFourierTransform.from_function(t_space, F)

# f2 should be equal to f
(f-f2).plot(show=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skipi-0.1.1.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

skipi-0.1.1-py3.8.egg (49.2 kB view details)

Uploaded Source

File details

Details for the file skipi-0.1.1.tar.gz.

File metadata

  • Download URL: skipi-0.1.1.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.2

File hashes

Hashes for skipi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 95b2ea301545afd99eb2b610779da1087eb08fd458ed02be25f4bbc43377607e
MD5 67f6a2cf74355ae582b0a36f0d71da72
BLAKE2b-256 225123128d705492d7d24ce2c369df0bfa14cee25156d81d07f4728027049773

See more details on using hashes here.

File details

Details for the file skipi-0.1.1-py3.8.egg.

File metadata

  • Download URL: skipi-0.1.1-py3.8.egg
  • Upload date:
  • Size: 49.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.3

File hashes

Hashes for skipi-0.1.1-py3.8.egg
Algorithm Hash digest
SHA256 00f4c8060d8dc8a57b6350c879a293ec7e5a1b1d6e43bbc0b4956ebd43a48383
MD5 a00539c59c60b86544ed321822234758
BLAKE2b-256 a99134bcbc263dd0f523f1c213441f0dad36111a6701529d3adf14c144cc5472

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page