Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert an anonymous function to a symbolic function in MATLAB?

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?

like image 807
Will Avatar asked Jul 04 '12 04:07

Will


People also ask

How do you convert symbolic to function handle MATLAB?

ht = matlabFunction( f ) converts the symbolic expression or function f to a MATLAB® function with handle ht .

What does anonymous function mean in MATLAB?

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.

How do you substitute values for symbols in MATLAB?

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).

Can you do Symbolic math in MATLAB?

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.


1 Answers

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...)

like image 115
Amro Avatar answered Sep 20 '22 00:09

Amro