multiroot()

library(rootSolve)
model <- function(x) c(F1= x[1] + x[2] + x[3]^2 - 12,
                       F2= x[1]^2 - x[2] + x[3] - 2,
                       F3= 2 * x[1] - x[2]^2 + x[3] - 1 )
(ss<-multiroot(model,c(1,1,1),useFortran=FALSE))
(ss<-multiroot(f=model,start=c(1,1,1)))
    • 実行
> help(multiroot)
> model <- function(x) c(F1= x[1] + x[2] + x[3]^2 - 12,
+                        F2= x[1]^2 - x[2] + x[3] - 2,
+                        F3= 2 * x[1] - x[2]^2 + x[3] - 1 )
> 
> # first solution
> (ss<-multiroot(model,c(1,1,1),useFortran=FALSE))
$root
[1] 1 2 3

$f.root
           F1            F2            F3 
 3.097771e-10  4.794410e-09 -8.682315e-09 

$iter
[1] 6

$estim.precis
[1] 4.595501e-09

> (ss<-multiroot(f=model,start=c(1,1,1)))
$root
[1] 1 2 3

$f.root
           F1            F2            F3 
 3.087877e-10  4.794444e-09 -8.678146e-09 

$iter
[1] 6

$estim.precis
[1] 4.593792e-09
  • 以下はヘルプの例のひとつ
    • M=X^3 をみたす行列X をもとめる
    • M=X^3Xの成分(今回は25個)に関する方程式とみなして解を求めることができる
library(rootSolve)
M<-matrix(1:25,nr=5,byrow=TRUE)
f2<-function(x)
 {
 X<-matrix(nr=5,x)
 X %*% X %*% X -M
 }
x<-multiroot(f2, start= runif(25) )$root
X<-matrix(nr=5,x)

X%*%X%*%X