Say I have a anonymous function f = @(x) x^2
and I want to convert this to a symbolic function. Is there a built in command for that?
ht = matlabFunction( f ) converts the symbolic expression or function f to a MATLAB® function with handle ht .
An anonymous function is a function that is not stored in a program file, but is associated with a variable whose data type is function_handle . Anonymous functions can accept multiple inputs and return one output. They can contain only a single executable statement.
Suppose you have a symbolic expression f which includes the symbol x and you wish to substitute for x another symbol c or a numerical value x0. Then you can use the general subs command g=subs(f,old,new) which in our cases would be g=subs(f,x,c) or g=subs(f,x,x0).
You can create, run, and share symbolic math code. In the MATLAB® Live Editor, you can get next-step suggestions for symbolic workflows. The toolbox provides functions in common mathematical areas such as calculus, linear algebra, algebraic and differential equations, equation simplification, and equation manipulation.
You could just pass it to SYM:
f = @(x) x^2;
g = sym(f)
But then most of the symbolic functions do that automatically when they receive a function handle (subs
, int
, etc...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With