sym2fun
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 (2023). sym2fun (https://www.mathworks.com/matlabcentral/fileexchange/65186-sym2fun), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Mathematics and Optimization > Symbolic Math Toolbox > Mathematics > Formula Manipulation and Simplification >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |