sfode


Namesfode JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryString Function of Ordinary Defferential Equations transformation.
upload_time2022-12-02 15:42:21
maintainer
docs_urlNone
authorXiaodu Hu
requires_python
licenseMIT
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 sfode 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 sfode 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 sfode 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": "sfode",
    "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/3f/89/a5a11fd955a8ed5410a9c8e33e13685c33a2460541fff7aef132f09253e9/sfode-0.0.2.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 sfode 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 sfode 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 sfode 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": "String Function of Ordinary Defferential Equations transformation.",
    "version": "0.0.2",
    "split_keywords": [
        "python",
        "ode",
        "string",
        "function"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "670b305b07537b29309de308c6ce228f",
                "sha256": "30271fc84c57103503b1a3f56fd34b2fb738a77d6ed5dd5d558b6829ebb15292"
            },
            "downloads": -1,
            "filename": "sfode-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "670b305b07537b29309de308c6ce228f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4130,
            "upload_time": "2022-12-02T15:42:21",
            "upload_time_iso_8601": "2022-12-02T15:42:21.990644Z",
            "url": "https://files.pythonhosted.org/packages/3f/89/a5a11fd955a8ed5410a9c8e33e13685c33a2460541fff7aef132f09253e9/sfode-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-02 15:42:21",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "sfode"
}
        
Elapsed time: 0.01317s