In essence, Newtons is the iterative way, so that the approximate solution (Taylor Formula) constantly approximation to the real solution, when the accuracy requirements, you can think of the approximate solution as the real solution
The following Newtons method is implemented in R language
Newtons<-function (fun,x,ep=1e-5,it_max=100) # #fun为需要求解的方程 (group), X is the initial solution, EP is the precision requirement, It_max is the maximum number of iterations
{
index<-0 # #指示是否完成迭代成功 to meet precision requirements
K<-1 # #迭代次数
while (K<=it_max)
{
X1<-x;obj<-fun (x);
X<-x-solve (obj$j,obj$f) # #obj $J is the jacobj matrix of equations (groups)
Norm<-sqrt ((x-x1)%*% (x-x1)) # #x (k+1) y and X (k) Accuracy difference
if (NORM<EP)
{
Index<-1
Break
}
K<-k+1
}
Obj<-fun (x);
List (ROOT=X,IT=K,INDEX=INDEX,FUNVAL=OBJ$F,JACOBI=OBJ$J)
}
Now to construct the equation (group) to be solved and its jacobj matrix
Funs<-function (x)
{
F<-c (x[1]^2+x[2]^2-5, (x[1]+1) *x[2]-(3*x[1]+1)) # #方程组
J<-matrix (c (2*x[1],2*x[2],x[2]-3,x[1]+1), nrow=2,byrow=t) # #jacobj矩阵, respectively, to X1 and X2 to seek first-order guidance
List (F=F,J=J)
}
Calculation Result:
> Newtons (funs,c (0,1))
$root
[1] 1 2
$it
[1] 6
$index
[1] 1
$FunVal
[1] 1.598721e-14 6.217249e-15
$Jacobi
[, 1] [, 2]
[1,] 2 4
[2,]-1 2
Interested students, you can use Debug (newtons) to debug the calculation process
Solving nonlinear equations with R language