sym2fun

sym2fun converts symbolic expressions to anonymous functions using vector symbolic arguments.

You are now following this Submission

sym2fun converts symbolic expressions to anonymous functions based on vector representations of the symbolic arguments.
syntax
f = sym2fun(fsym, vars, symVec1, repVec1, ..., symVecN, repVecN)

Description
f = sym2fun( __ ) converts the symbolic statement fsym to an anonymous function handle f with the input arguments listed in vars. The input pairs symVec and repVec contain the symbolic vectors and the corresponding numerical vector representations. The data types for the input arguments are:
f: an anonymous function handle
fsym: an NxM symbolic matrix
vars: a cell array that contains the input names for f (that is f = f(vars{1}, vars{2}, ..., vars{p})
symVec: A vector of symbolic arguments
repVec: A cell array that contains the replacement names for each of the entries in symVec.

Example
>> x = sym('x%d',[3,1],'real');
>> y = sym('y%d',[3,1],'real');
>> p = [2*cos(x(1)) + 7*y(1)^2; sin(x(2)+y(2))];
>> J = jacobian(p,[x;y]) + randi([-10 10],2,4);
>> f = sym2fun(J, {'x','y'}, x, {'x(1)','x(2)'}, y, {'y(1)','y(2)'});

Cite As

Siamak (2026). sym2fun (https://se.mathworks.com/matlabcentral/fileexchange/65186-sym2fun), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
1.0.0.0