Name | odesf JSON |
Version |
0.0.4
JSON |
| download |
home_page | |
Summary | Ordinary Differential Equations String Function generator. |
upload_time | 2022-12-02 16:42:11 |
maintainer | |
docs_url | None |
author | Xiaodu Hu |
requires_python | |
license | MIT |
keywords |
python
ode
string
function
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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()`
```python
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
```python
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
```python
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_[]);"
```
Raw data
{
"_id": null,
"home_page": "",
"name": "odesf",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "python,ode,string,function",
"author": "Xiaodu Hu",
"author_email": "xiaodu.hu@outlook.com",
"download_url": "https://files.pythonhosted.org/packages/86/6e/7657ae17d5c90390535020e2d1e29764c7638a35340231bdaa09ed276993/odesf-0.0.4.tar.gz",
"platform": null,
"description": "# String format function of ODEs\nThis package provides a simple function - transform a list of ODEs in string format into a string of a function in Python/C++.\n\nExamples are as follows.\n\n## For python\n\nTo transform a list of ODE strings into function string format:\n\n- the left hand side must be written with derivitive form `d()/d()`\n```python\nfrom odesf import eq_to_pyfunc_string\n\nstiff_equation = ['dy/dt = z + t',\n 'dz/dt = -100 * y * t']\n\nfuncstr = eq_to_pyfunc_string(stiff_equation)\n\nprint(funcstr)\n\n>> \"def func(_x_, _y_, _f_): _f_[0] = _y_[1] + _x_; _f_[1] = -100 * _y_[0] * _x_;\"\n```\n\n\n\nIf constants exist, a list of constant equations must be passed over:\n\n- The constant variable name at the left hand side must be the same as in ODE strings\n```python\nfrom odesf import eq_to_pyfunc_string\n\nlorenz_equation_strs = ['dx/dt = sigma * (y - x)',\n 'dy/dt = rho * x - y - x * z',\n 'dz/dt = x * y - beta * z']\n\nlorenz_constants = ['sigma = 10e0',\n 'rho = 28e0',\n 'beta = 8e0 / 3e0']\n\nfuncstr = eq_to_pyfunc_string(lorenz_equation_strs, lorenz_constants)\n\nprint(funcstr)\n\n>> \"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];\"\n\n```\n\n\n\n## For C++\n\nUnlike for python, the result is a tuple:\n\n- function string in `.cpp` format\n- function head string in `.h` format\n\n```python\nfrom odesf import eq_to_cfunc_string\n\nstiff_equation = ['dy/dt = z + t',\n 'dz/dt = -100 * y * t']\n\nfuncstr, funch = eq_to_cfunc_string(stiff_equation)\n\nprint(funcstr)\nprint(funch)\n\n>> \"Function str: void template_func(double _x_, double _y_[], double _f_[]) { _f_[0] = _y_[1] + _x_; _f_[1] = -100 * _y_[0] * _x_; }\"\n>> \"Head str: void template_func(double _x_, double _y_[], double _f_[]);\"\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Ordinary Differential Equations String Function generator.",
"version": "0.0.4",
"split_keywords": [
"python",
"ode",
"string",
"function"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "9f137d85f12ce1bbb4563b8f07fda01b",
"sha256": "82d18244705603225d2534e6965fe4b3ec7958894bb8108cf0f830ad93046419"
},
"downloads": -1,
"filename": "odesf-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "9f137d85f12ce1bbb4563b8f07fda01b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3867,
"upload_time": "2022-12-02T16:42:11",
"upload_time_iso_8601": "2022-12-02T16:42:11.901220Z",
"url": "https://files.pythonhosted.org/packages/86/6e/7657ae17d5c90390535020e2d1e29764c7638a35340231bdaa09ed276993/odesf-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-02 16:42:11",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "odesf"
}