This function utilizes Python's SymPy module to provide symbolic capabilities for those of us who do not have the Symbolic Toolbox or a version of Matlab with Python support at our disposal. The function passes strings to and from Python via the System command. Computation of the result is easily accomplished via the vectorize and inline functions.
result = symeval('integrate','"x^2+3x-4"','x');
y = vectorize(inline(result));
This can be slow since the Python interpreter is started and shutdown every time the function is called. However, successive calls are sped up due to OS caching.
Another option is to use the pymex module posted on this file exchange:
The best way is to just call the library directly with a version of MATLAB that supports Python.
Jonathan Lister (2021). SymPy CAS in MATLAB (https://www.mathworks.com/matlabcentral/fileexchange/42787-sympy-cas-in-matlab), MATLAB Central File Exchange. Retrieved .
The entry "Maxima Cas in Matlab" works better IMO.
result = symeval('integrate','"(cos(x)/x) - (sin(x)/x^2)"','x')
f = vectorize(inline(result));
make sure the equation string that you pass in is enclosed within a double quotes as well as the single quote...
funstr = '"x^2 + 2*x + 1"'
result = symeval('factor',funstr)
Inspired by: MAXIMA CAS in MATLAB
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!