Skip to main content

Ordinary Differential Equations String Function generator.

Project description

String format function of ODEs

This package provides a simple function - transform a list of ODEs in string format into a string of a function in Python/C++.

Examples are as follows.

For python

To transform a list of ODE strings into function string format:

  • the left hand side must be written with derivitive form d()/d()
from odesf import eq_to_pyfunc_string

stiff_equation = ['dy/dt = z + t',
                  'dz/dt = -100 * y * t']

funcstr = eq_to_pyfunc_string(stiff_equation)

print(funcstr)

>> "def func(_x_, _y_, _f_): _f_[0] = _y_[1] + _x_; _f_[1] = -100 * _y_[0] * _x_;"

If constants exist, a list of constant equations must be passed over:

  • The constant variable name at the left hand side must be the same as in ODE strings
from odesf import eq_to_pyfunc_string

lorenz_equation_strs = ['dx/dt = sigma * (y - x)',
                        'dy/dt = rho * x - y - x * z',
                        'dz/dt = x * y - beta * z']

lorenz_constants = ['sigma = 10e0',
                    'rho = 28e0',
                    'beta = 8e0 / 3e0']

funcstr = eq_to_pyfunc_string(lorenz_equation_strs, lorenz_constants)

print(funcstr)

>> "def func(_x_, _y_, _f_): sigma = 10e0; rho = 28e0; beta = 8e0 / 3e0;  _f_[0] = sigma * (_y_[1] - _y_[0]); _f_[1] = rho * _y_[0] - _y_[1] - _y_[0] * _y_[2]; _f_[2] = _y_[0] * _y_[1] - beta * _y_[2];"

For C++

Unlike for python, the result is a tuple:

  • function string in .cpp format
  • function head string in .h format
from odesf import eq_to_cfunc_string

stiff_equation = ['dy/dt = z + t',
                  'dz/dt = -100 * y * t']

funcstr, funch = eq_to_cfunc_string(stiff_equation)

print(funcstr)
print(funch)

>> "Function str: void template_func(double _x_, double _y_[], double _f_[]) { _f_[0] = _y_[1] + _x_; _f_[1] = -100 * _y_[0] * _x_; }"
>> "Head str:  void template_func(double _x_, double _y_[], double _f_[]);"

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

odesf-0.0.4.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file odesf-0.0.4.tar.gz.

File metadata

  • Download URL: odesf-0.0.4.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.0

File hashes

Hashes for odesf-0.0.4.tar.gz
Algorithm Hash digest
SHA256 82d18244705603225d2534e6965fe4b3ec7958894bb8108cf0f830ad93046419
MD5 9f137d85f12ce1bbb4563b8f07fda01b
BLAKE2b-256 866e7657ae17d5c90390535020e2d1e29764c7638a35340231bdaa09ed276993

See more details on using hashes here.

Supported by

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