Main Content

Create Symbolic Functions

Symbolic functions represent math functions. Use symbolic functions for differentiation, integration, solving ODEs, and other math operations. Create symbolic functions by using syms.


Symbolic functions must be functions of symbolic variables. The Symbolic Math Toolbox™ currently does not support composite symbolic functions, or symbolic functions that are functions of another symbolic functions.

Create a symbolic function f with variables x and y by using syms. Creating f automatically creates x and y.

syms f(x,y)

Assign a mathematical expression to f.

f(x,y) = x^2*y
f(x, y) =

Find the value of f at (3,2).

ans =

Symbolic functions accept array inputs. Calculate f for multiple values of x and y.

xVal = 1:5;
yVal = 3:7;
ans =
[ 3, 16, 45, 96, 175]

You can differentiate symbolic functions, integrate or simplify them, substitute their arguments with values, and perform other mathematical operations. For example, find the derivative of f(x,y) with respect to x. The result dfx is also a symbolic function.

dfx = diff(f,x)
dfx(x,y) =

Calculate df(x,y) at x = y + 1.

ans =
2*y*(y + 1)

If you are creating a constant function, such as f(x,y) = 1, you must first create f(x,y). If you do not create f(x,y), then the assignment f(x,y) = 1 throws an error.

Related Topics