This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

symfun

Create symbolic functions

Syntax

f(inputs) = formula
f = symfun(formula,inputs)

Description

example

f(inputs) = formula creates the symbolic function f. For example, f(x,y) = x + y. The symbolic variables in inputs are the input arguments. The symbolic expression formula is the body of the function f.

f = symfun(formula,inputs) is the formal way to create a symbolic function.

Examples

collapse all

Define the symbolic function x + y. First, create the function by using syms. Then define the function.

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

Find the value of f at x = 1 and y = 2.

f(1,2)
ans =
3

Define the function again by using the formal way.

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

Return the body of a symbolic function by using formula. You can use the body for operations such as indexing into the function. Return the arguments of a symbolic function by using argnames.

Index into the symbolic function [x^2, y^4]. Since a symbolic function is a scalar, you cannot directly index into the function. Instead, index into the body of the function.

syms f(x,y)
f(x,y) = [x^2, y^4];

fbody = formula(f);
fbody(1)
fbody(2)
ans =
x^2
ans =
y^4

Return the arguments of the function.

fvars = argnames(f)
fvars =
[ x, y]

Input Arguments

collapse all

Function body, specified as a symbolic expression, vector of symbolic expressions, or matrix of symbolic expressions.

Example: x + y

Input argument or arguments of a function, specified as a symbolic variable or an array of symbolic variables, respectively.

Example: [x,y]

Output Arguments

collapse all

Function, returned as a symbolic function (symfun data type).

Introduced in R2012a