matlab 中fzero,matlab – 一个变量的fzero和fsolve之间的差异

  • Post author:
  • Post category:其他


就在这里.我只想提到两者之间最直接的区别:

07000 can be used to solve for the zero of a single variable equation. However, 07001 will find the zero if and only if the function crosses the x-axis.

这是一个简单的例子:考虑函数f = x ^ 2.该函数对于x的所有实数值都是非负的.这在x = 0时有一个根.我们将匿名函数定义为f =@(x)x.^2;并尝试使用这两种方法找到根.

使用fsolve

options=optimset(‘MaxIter’,1e3,’TolFun’,1e-10);

fsolve(f,0.1,options)

Equation solved.

fsolve completed because the vector of function values is near zero

as measured by the selected value of the function tolerance, and

the problem appears regular as measured by the gradient.

ans =

1.9532e-04

不是零,而是接近.

使用fzero

fzero(f,0.1)

Exiting fzero: aborting search for an interval containing a sign change

because NaN or Inf function value encountered during search.

(Function value at -1.37