Main Content

compose

Functional composition

Description

example

compose(f,g) returns f(g(y)) where f = f(x) and g = g(y). Here x is the symbolic variable of f as defined by symvar and y is the symbolic variable of g as defined by symvar.

example

compose(f,g,z) returns f(g(z)) where f = f(x), g = g(y), and x and y are the symbolic variables of f and g as defined by symvar.

example

compose(f,g,x,z) returns f(g(z)) and makes x the independent variable for f. That is, if f = cos(x/t), then compose(f,g,x,z) returns cos(g(z)/t) whereas compose(f,g,t,z) returns cos(x/g(z)).

example

compose(f,g,x,y,z) returns f(g(z)) and makes x the independent variable for f and y the independent variable for g. For f = cos(x/t) and g = sin(y/u), compose(f,g,x,y,z) returns cos(sin(z/u)/t) whereas compose(f,g,x,u,z) returns cos(sin(y/z)/t).

Examples

collapse all

Show functional composition by creating functions from existing functions.

Declare functions.

syms x y z t u
f = 1/(1 + x^2);
g = sin(y);
h = x^t;
p = exp(-y/u);

Compose functions with different functions and variables as inputs.

a = compose(f,g)
a =
1/(sin(y)^2 + 1)
b = compose(f,g,t)
b =
1/(sin(t)^2 + 1)
c = compose(h,g,x,z)
c =
sin(z)^t
d = compose(h,g,t,z)
d =
x^sin(z)
e = compose(h,p,x,y,z)
e =
exp(-z/u)^t

Input Arguments

collapse all

Input, specified as a symbolic function or expression.

Input, specified as a symbolic function or expression.

Symbolic variable, specified as a symbolic variable.

Symbolic variable, specified as a symbolic variable.

Symbolic variable, specified as a symbolic variable.

Version History

Introduced before R2006a

See Also

| |