MATLAB 内联函数 与匿名函数的基本用法(笔记)

inline 函数

官方文档

inline Construct inline object.

inline will be removed in a future release. Use anonymous
functions instead.

inline(EXPR) constructs an inline function object from the
MATLAB expression contained in the string EXPR.  The input
arguments are automatically determined by searching EXPR
for variable names (see SYMVAR). If no variable exists, 'x'
is used.

inline(EXPR, ARG1, ARG2, ...) constructs an inline
function whose input arguments are specified by the
strings 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', ..., 'PN'.

Examples:
  g = inline('t^2')
  g = inline('sin(2*pi*f + theta)')
  g = inline('sin(2*pi*f + theta)', 'f', 'theta')
  g = inline('x^P1', 1)

% 使用inline 创建初等函数的程序很简洁
%要计算多个点的函数值是,注意四种数组运算的使用

% 用法:
%1据expr建立内联函数,函数自变量符号根据表达式自动确定;
%2: 定义是指定自变量符号
%3:自变量符号为x,p1

%定义匿名函数
% 定义方法; @(参数列表)(函数列表)
% 例 f=@(x,y)(x.^2+y.^2)
%val=f(1:5,11:15)

返回:
% val =

122 148 178 212 250

你可能感兴趣的:(MATLAB,数学实验)