Convert a symbolic object X with variables a1,a2,a3,...,aN to a function handle (anonymous function) hX(a), where a=[a1,a2,a3,...,aN].
Updated 16 Jun 2023

View License

Convert a symbolic object X with variables a1,a2,a3,...,aN to a function handle hX. The handle hX can evaluated by hX(a), where "a" is an array of variables a=[a1,a2,a3,...,aN]. A function handle hX is an anonymous function (not stored in a program file).
There are two distinct variations in the usage of SYM2FHANDLE:
1. Symbolic object X has N variables a1,a2,a3,...,aN.
For an object X(a1,a2,a3,...,aN), SYM2FHANDLE converts X to hX(a), where the input a is an array with the length of N.
2. Symbolic object X has N variables and a domain variable.
For an object e.g. X(a1,a2,a3,...,aN,w), SYM2FHANDLE converts X to hX(a,w). Here, w is a "domain". Domain can be e.g. time, frequency or complex frequency variable (s or z).
SYM2FHANDLE outputs a function handle and an element-wise version of the function handle. The latter can be used to evaluate domain as an array. A good example would be generating a frequency response of a transfer function.
The class of the array and domain can be anything that MATLAB can evaluate. For instance, if the domain is an LTI object, the variable array cannot be symbolic.
The possibilities of SYM2FHANDLE are endless, but here's my favourite: For an equation (or a system of equations) converted to a handle hX, you can use the handle as a target function to optimization toolbox function such as FSOLVE or LSQNONLIN. The outcome is the optimized values of a1,a2,a3,...,aN.

Cite As

Marko Neitola (2024). sym2fhandle (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2023a
Compatible with R14SP1 and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes