这fzero
function attempts to find a root of one equation with one variable. You can call this function with either a one-element starting point or a two-element vector that designates a starting interval. If you givefzero
一个起点X0
,,,,fzero
首先搜索该函数更改符号的时间间隔。如果发现间隔,fzero
返回附近函数更改符号的值。如果找不到这样的间隔,fzero
返回南
。Alternatively, if you know two points where the function value differs in sign, you can specify this starting interval using a two-element vector;fzero
保证可以缩小间隔并返回符号更改附近的值。
以下各节包含两个示例,这些示例说明了如何使用起始间隔和起点来找到函数的零。示例使用该功能humps.m
,,,,which is provided with MATLAB®。这following figure shows the graph of驼峰
。
X= -1:.01:2; y = humps(x); plot(x,y) xlabel('X');ylabel('humps(x)') 网格on
You can control several aspects of thefzero
通过设置选项来函数。您使用最佳集
。Options include:
Choosing the amount of displayfzero
生成 - 看Set Options,,,,Using a Starting Interval,,,,一个nd使用起点。
选择各种控制方式fzero
determines it is at a root — seeSet Options。
Choosing a plot function for observing the progress offzero
towards a root — seePlot Functions。
Using a custom-programmed output function for observing the progress offzero
towards a root — see输出功能。
图驼峰
表明该函数为负X= -1
和积极的X= 1
。您可以通过计算来确认驼峰
在这两个点上。
驼峰(1)
一个ns = 16
驼峰(-1)
一个ns = -5.1378
Consequently, you can use[-1 1]
作为开始间隔fzero
。
迭代算法fzero
发现越来越小的子间隔[-1 1]
。对于每个子间隔,驼峰
differs at the two endpoints. As the endpoints of the subintervals get closer and closer, they converge to zero for驼峰
。
显示进度fzero
在每次迭代中,设置展示
option to迭代
using the最佳集
功能。
选项=最佳集('Display',,,,'iTer');
然后致电fzero
一个s follows:
一个= fzero(@humps,[-1 1],options)
Func-count x f(x) Procedure 2 -1 -5.13779 initial 3 -0.513876 -4.02235 interpolation 4 -0.513876 -4.02235 bisection 5 -0.473635 -3.83767 interpolation 6 -0.115287 0.414441 bisection 7 -0.115287 0.414441 interpolation 8 -0.132562 -0.0226907 interpolation 9 -0.131666 -0.0011492 interpolation 10 -0.131618 1.88371e-07 interpolation 11 -0.131618 -2.7935e-11 interpolation 12 -0.131618 8.88178e-16 interpolation 13 -0.131618 8.88178e-16 interpolation Zero found in the interval [-1, 1]
a = -0.1316
每个值X
represents the best endpoint so far. The程序
column tells you whether each step of the algorithm uses bisection or interpolation.
You can verify that the function value at一个
通过输入接近零
的线条(a)
ANS = 8.8818e-16
假设您不知道两个点的功能值驼峰
differ in sign. In that case, you can choose a scalarX0
一个s the starting point forfzero
。fzero
first searches for an interval around this point on which the function changes sign. Iffzero
找到这样的间隔,它以上一节中描述的算法进行。如果找不到这样的间隔,fzero
返回南
。
For example, set the starting point to-0.2
, 这展示
option to迭代
,,,,一个nd callfzero
:
选项=最佳集('Display',,,,'iTer');a = fzero(@humps,-0.2,选项)
Search for an interval around -0.2 containing a sign change: Func-count a f(a) b f(b) Procedure 1 -0.2 -1.35385 -0.2 -1.35385 initial interval 3 -0.194343 -1.26077 -0.205657 -1.44411 search 5 -0.192 -1.22137-0.208 -1.4807 search 7 -0.188686 -1.16477 -0.211314 -1.53167 search 9 -0.184 -1.08293 -0.216 -1.60224 search 11 -0.177373 -0.963455 -0.222627 -1.69911 search 13 -0.168 -0.786636 -0.232 -1.83055 search 15 -0.154745 -0.51962-0.245255 -2.00602搜索17 -0.136 -0.104165 -0.264 -2.23521搜索18 -0.10949 0.572246 -0.264 -2.23521搜索搜索在此间隔[-0.10.10949,-0.264]中搜索为零,0.572246 initial 19 -0.140984 -0.219277 interpolation 20 -0.132259 -0.0154224 interpolation 21 -0.131617 3.40729e-05 interpolation 22 -0.131618 -6.79505e-08 interpolation 23 -0.131618 -2.98428e-13 interpolation 24 -0.131618 8.88178e-16 interpolation 25 -0.131618 8.88178E-16在间隔[-0.10949,-0.264]中发现的插值零
a = -0.1316
每个迭代时当前子间隔的终点都在标题下列出一个
一个ndb
,,,,while the corresponding values of驼峰
在端点处列出f(a)
一个ndf(b)
, 分别。
这endpoints一个
一个ndb
一个re not listed in any specific order:一个
可以大于b
或少于b
。
在前九个步骤中,驼峰
is negative at both endpoints of the current subinterval, which is shown in the output. At the tenth step, the sign of驼峰
在端点上是积极的,-0.10949
,但端点为负-0.264
。从这一点开始,算法继续缩小间隔[-0.10949 -0.264]
,,,,一个s described in the previous section, until it reaches the value-0.1316
。