Contents Previous Next Subchapters Current Chapters-> interp interp1 lagrange polyfit smospl cubespl cubeval interp2 mlmode_interp2 snewton brent linlsq linlsqb nlsq dnlsq nlsqbox dnlsqb conjdir neldermead conjgrad minline lemke Qpos Qbox Qpro sqp relative fordiff cendiff autodiff testder testgrad testhess Parent Chapters-> Omatrix6 fit brent Search Tools-> contents reference index search

Brent's Method for Multiple Nonlinear Equations Without Derivatives
 Syntax `[x, nfun] = brent(function `f`, `fval`, `xini`, `step`, `mfun`)` See Also snewton , dnlsq

Description
Solves multiple nonlinear scalar valued equations of a scalar argument using a combination of bisection, linear interpolation and Brent's method. The return value x is matrix with the same type and dimension as xini, such that ```      f  (x  ) = fval        ij  ij        ij ```The real, double-precision or complex matrix xini specifies the starting point when Brent's method is applied to solve the corresponding equation above. The matrix fval has the same type and dimension as xini and specifies the right hand side of the equation. The scalar step has the same type as x and specifies the initial step size with respect to `x` for bracketing the minimum. ``` ```The integer scalar mfun specifies the maximum number of evaluations of f to attempt. If the method cannot not converge in mfun calls to f, `brent` returns the current estimate of x and with ```      nfun = mfun + 1 ```Otherwise, the return value of nfun is the number of evaluations of f that was used by `brent` ``` ```f`(`x```) ```The returns the element-by-element a matrix valued function f`(`x`)` where x is a matrix with the same type and dimension as xini.

Example
The following example uses `brent` to compute the square roots of 1, 2, 3 and 4 (though we would normally use the sqrt function for this task). ```      clear      function f(x) begin           return x^2.      end      fval  = double(seq(4))      xini  = 1d0 + rand(4, 1)      step  = .1d0      mfun  = 100      [x, nfun] = brent(function f, fval, xini, step, mfun)       print x ``` returns ```      {      1      1.41421      1.73205      2      } ``` which are the square roots of 1, 2, 3, and 4 respectively.