symfun
Symbolic function of named input variables.
Category: Symbolic Computations in MATLAB > Symbolic Variables, Expressions, Functions, and Preferences
Syntax
f = symfun(expr, vars)
Creates the function f(vars) = expr.
syms f(x, y)
Declares a symbolic function and its arguments; define it later with f(x, y) = expr.
Description
A symfun is an expression bundled with its list of input variables. Calling it with values substitutes them, so f(2, 3) evaluates the formula at that point, and calling it with symbolic expressions gives the composed expression. Operations such as diff, int and arithmetic between symfuns return symfuns again.
argnames returns the variable list and formula the expression. The declaration form syms f(x) followed by f(x) = expr is the most common way to build one.
Input arguments
expr- Symbolic expression that defines the function.
vars- Input variables of the function.
Output arguments
f- Symbolic function (class
symfun) that can be called with numbers or expressions.
Example
Defining and calling a function
syms f(x, y)
f(x, y) = x*y + 1;
f(2, 3)
class(f)
argnames(f)
Output
ans = 7
ans = 'symfun'
ans =
[x, y]