sym2pyfun

Version 1.0.0 (71.1 KB) by Timo
Convert Matlab symbolic functions to python function
115 Downloads
Updated 27 Apr 2019

There exist two main functions that are `fprintMatPy.m` and `fprintMatPy2.m` which convert a symbolic expression to a python function.
`fprintMatPy.m` extract the function as is, where `fprintMatPy2.m` is able to split long equations (s.t. consist out of more characters than a given value) to make them parseable by python and cython.
For more details look at the scripts' explainations.
The functions `fprintMatPy*.m` extend `fprintMatPy*.m` to print symbolic matrices, where each row and colum are extracted to one function.

Examples:

`syms a b c; fprintMatPy('test', {'a', 'b', 'c'}, [a*b+c, a^b])` produces output to `test.py`:

def test_1_1(a, b, c):
return c + a*b

def test_1_2(a, b, c):
return a**b

`syms a b c d k; fprintMatPy2('test1', {'a', 'b', 'c', 'd', 'k'}, a*b^k+c+d, 5)` produces output to `test1.py`:

def test1(a, b, c, d, k):
_1 = c
_2 = d
_3 = a*b**k
_0 = _1+_2+_3
return _0

`syms a b c d k; fprintMatPy2('test2', {'a', 'b', 'c', 'd', 'k'}, a*b^k+c+d, 0)` produces output to `test2.py`:

def test(a, b, c, d, k):
_1 = c
_2 = d
_4 = a
_6 = b
_7 = k
_5 = _6**_7
_3 = _4*_5
_0 = _1+_2+_3
return _0

Cite As

Timo (2024). sym2pyfun (https://github.com/tik0/sym2pyfun), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
1.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.