matlab中的feval函数怎么用

希望举一个简单的例子

第1个回答  推荐于2016-02-21
feval

Evaluate function
Syntax

[y1, y2, ...] = feval(fhandle, x1, ..., xn)
[y1, y2, ...] = feval(function, x1, ..., xn)
Description

[y1, y2, ...] = feval(fhandle, x1, ..., xn) evaluates the function handle, fhandle, using arguments x1 through xn. If the function handle is bound to more than one built-in or M-file, (that is, it represents a set of overloaded functions), then the data type of the arguments x1 through xn determines which function is dispatched to.

Note It is not necessary to use feval to call a function by means of a function handle. This is explained in Calling a Function Using Its Handle in the MATLAB? Programming Fundamentals documentation.

[y1, y2, ...] = feval(function, x1, ..., xn). If function is a quoted string containing the name of a function (usually defined by an M-file), then feval(function, x1, ..., xn) evaluates that function at the given arguments. The function parameter must be a simple function name; it cannot contain path information.
Remarks

The following two statements are equivalent.

[V,D] = eig(A)
[V,D] = feval(@eig, A)

Examples

The following example passes a function handle, fhandle, in a call to fminbnd. The fhandle argument is a handle to the humps function.

fhandle = @humps;
x = fminbnd(fhandle, 0.3, 1);

The fminbnd function uses feval to evaluate the function handle that was passed in.

function [xf, fval, exitflag, output] = ...
fminbnd(funfcn, ax, bx, options, varargin)
.
.
.
fx = feval(funfcn, x, varargin{:});本回答被提问者采纳
第2个回答  推荐于2018-04-11
很简单的,feval用来计算指定函数在某点的函数值,如a=feval(fun,x),就相当于a=fun(x),如

>>a=feval(@(x)(x^2+1),1)

a =

2

>> a=feval(@(x)(x^2+1),2)

a =

5本回答被网友采纳
相似回答