symfun

Create symbolic functions

Syntax

f = symfun(formula,inputs)

Description

f = symfun(formula,inputs) creates the symbolic function f and symbolic variables inputs representing its input arguments. The symbolic expression formula defines the body of the function f.

Input Arguments

formula

Symbolic expression or vector or matrix of symbolic expressions. This argument represents the body of f. If it contains other symbolic variables besides inputs, those variables must already exist in the MATLAB® workspace.

inputs

Array that contains input arguments of f. For each argument, symfun creates a symbolic variable. Argument names must begin with a letter and can contain only alphanumeric characters.

Output Arguments

f

Symbolic function. The name of a symbolic function must begin with a letter and contain only alphanumeric characters.

Examples

Create the symbolic variables x and y. Then use symfun to create the symbolic function f(x, y) = x + y:

syms x y
f = symfun(x + y, [x y])
f(x, y) =
x + y

Create the symbolic variables x and y. Then use symfun to create an arbitrary symbolic function f(x, y). An arbitrary symbolic function does not have a mathematical expression assigned to it.

syms x y
f = symfun(sym('f(x, y)'), [x y])
f(x, y) =
f(x, y)

Alternatives

Use the assignment operation to simultaneously create a symbolic function and define its body. The arguments x and y must be symbolic variables in the MATLAB workspace.

syms x y
f(x, y) = x + y

Use syms to create an arbitrary symbolic function f(x, y). The following command creates the symbolic function f and the symbolic variables x and y.

syms f(x, y)

Use sym to create an arbitrary symbolic function f(x, y). The arguments x and y must be symbolic variables in the MATLAB workspace.

syms x y
f(x, y) = sym('f(x, y)')
Was this topic helpful?