MATLAB Functions | Help Desk |
inline
Construct an inline object
g = inline(expr
) g = inline(expr,arg1,arg2, ...
) g = inline(expr,
n
)
inline(
expr
)
constructs an inline function object from the MATLAB expression contained in the string expr
. The input argument to the inline function is automatically determined by searching expr
for an isolated lower case alphabetic character, other than i
or j
, that is not part of a word formed from several alphabetic characters. If no such character exists, x
is used. If the character is not unique, the one closest to x
is used. If there is a tie, the one later in the alphabet is chosen.
constructs an inline function whose input arguments are specified by the strings inline(
expr
,
arg1
,
arg2
, ...)
arg1
, arg2
,...
. Multicharacter symbol names may be used.
inline(
expr
,n)
, where n
is a scalar, constructs an inline function whose input arguments are x
, P1
, P2
, ...
Three commands related to inline
allow you to examine an inline function object and determine how it was created.
char(
fun
)
returns the string that can be used to recreate the inline function object. This is the opposite of the constructor inline
.
argname
s(fun
) returns the names of the input arguments of the inline object fun
as a cell array of strings.
formula
(fun
) returns the formula for the inline object fun
.
Create a simple inline function to square a number:
g = inline('t^2')
g =
Inline function:
g(t) = t^2
char(g)
ans =
inline('t^2', 't')
Create an inline function to compute the formula
:
g = inline('3*sin(2*x.^2)') g = Inline function: g(x) = 3*sin(2*x.^2) argnames(g) ans = 'x' formula(g) ans = 3*sin(2*x.^2) g(pi) ans = 2.3306 g(2*pi) ans = -1.2151 fmin(g,pi,2*pi) ans = 3.8630