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 snewton Search Tools-> contents reference index search

Newton's Method For Multiple Nonlinear Equations In One Variable
 Syntax `snewton(function `f`, function `df`, `fval`, `xini`, `mitr`)` See Also brent , dnlsq

Description
Inverts a nonlinear scalar valued function of a scalar argument. The return value is a matrix `x` with the same type and dimension as fval, such that ```      f(x   ) = fval      for i = 1, ... , M, and j = 1, ... , N         i,j        i,j ```where `M` and `N` are the row and column dimension of fval respectively. The matrix xini has the same type and dimension as fval. The (i,j)-th element of xini is the starting point when Newton's method is applied to solve the corresponding equation above. ``` ```The integer scalar mitr specifies the maximum number of Newton steps to attempt. If the method does not converge in mitr iterations, `snewton` returns the current estimate. If you suspect this method might fail, you should check that the equations are solved by the return value. (Note the equations may be solved for a subset of the indices.) ``` ```f`(`x```) ```The (i,j)-th element of the return value of f`(`x`)` is the value `f(x(i, j))`. The argument x and the return value `f(x)` have the same type and dimension as fval. ``` ```df`(`x```) ```The (i,j)-th element of the return value of df`(`x`)` is the derivative of `f` evaluated at the point `x(i, j)`. The argument x and the return value `df(x)` have the same type and dimension as fval.

Example
The following example uses `snewton` to compute the square root of the integers between 1 and 4 (though we would normally use the sqrt function for this task). The initial starting points are random numbers between zero and one. ```      function f(x) begin           return x^2.      end      function df(x) begin           return 2. * x      end      fval   = real(seq(4))      xini   = rand(4, 1)      mitr   = 10      snewton(function f, function df, fval, xini, mitr) ``` returns ```      {      1      1.41421      1.73205      2      } ``` which are the square roots of 1, 2, 3, and 4, respectively.