求解非线性方程组

Solve system of non-linear equations

我正在尝试求解以下四个方程组。我试过使用 "rootSolve" 包,但似乎无法通过这种方式找到解决方案。

我使用的代码如下:

model <- function(x) {
F1 <- sqrt(x[1]^2 + x[3]^2) -1
F2 <- sqrt(x[2]^2 + x[4]^2) -1
F3 <- x[1]*x[2] + x[3]*x[4]
F4 <- -0.58*x[2] - 0.19*x[3]
c(F1 = F1, F2 = F2, F3 = F3, F4 = F4)
}
(ss <- multiroot(f = model, start = c(0,0,0,0)))

但它给我以下错误:

Warning messages:
1: In stode(y, times, func, parms = parms, ...) :
error during factorisation of matrix (dgefa);         singular matrix
2: In stode(y, times, func, parms = parms, ...) : steady-state not reached

我已经按照另一个类似答案中的建议更改了起始值,对于某些人我可以找到解决方案。 然而,这个系统——根据我使用的来源——应该有一个唯一标识的解决方案。 关于如何解决这个系统的任何想法?

谢谢!

以上警告指出,使用您提供给 multiroot 的起始值无法找到最佳解决方案。

让我们试试这个 -

library(rootSolve)

model <- function(x) {
  F1 <- sqrt(x[1]^2 + x[3]^2) - 1
  F2 <- sqrt(x[2]^2 + x[4]^2) - 1
  F3 <- x[1]*x[2] + x[3]*x[4]
  F4 <- -0.58*x[2] - 0.19*x[3]
  c(F1 = F1, F2 = F2, F3 = F3, F4 = F4)
  }

#solution
(ss <- multiroot(f = model, start = c(1.5, 0, 0.5, 0)))

它给出

> ss
$root
[1]  1.000000e+00  4.752703e-12 -1.450825e-11  1.000000e+00

$f.root
           F1            F2            F3            F4 
 3.404610e-12  3.494982e-13 -9.755549e-12  1.929753e-20 

$iter
[1] 7

$estim.precis
[1] 3.377414e-12

经过多次试验,我发现每当我改变它的起始值时,我每次都会得到几乎相同的结果(即 1, 0, 0, 1)。

你的方程组有多个解。 我用不同的包来解决你的系统:nleqslv 如下:

library(nleqslv)

model <- function(x) {
   F1 <- sqrt(x[1]^2 + x[3]^2) - 1
   F2 <- sqrt(x[2]^2 + x[4]^2) - 1
   F3 <- x[1]*x[2] + x[3]*x[4]
   F4 <- -0.58*x[2] - 0.19*x[3]
   c(F1 = F1, F2 = F2, F3 = F3, F4 = F4)
}

#find solution
xstart  <-  c(1.5, 0, 0.5, 0)
nleqslv(xstart,model)

这得到了与 Prem 的答案相同的解决方案。

但是您的系统有多个解决方案。 包 nleqslv 提供了一个函数,用于在给定不同起始值的矩阵的情况下搜索解决方案。你可以使用这个

set.seed(13)
xstart <- matrix(runif(400,0,2),ncol=4)
searchZeros(xstart,model)

(注:不同的种子可能无法找到全部四种解法)

您会看到有四种不同的解决方案:

$x
     [,1]          [,2]          [,3] [,4]
[1,]   -1 -1.869055e-10  5.705536e-10   -1
[2,]   -1  4.992198e-13 -1.523934e-12    1
[3,]    1 -1.691309e-10  5.162942e-10   -1
[4,]    1  1.791944e-09 -5.470144e-09    1
.......

这清楚地表明精确解如以下矩阵所示 [​​=23=]

xsol <- matrix(c(1,0,0,1,
                 1,0,0,-1,
                -1,0,0,1,
                -1,0,0,-1),byrow=TRUE,ncol=4)

然后做

model(xsol[1,])
model(xsol[2,])
model(xsol[3,])
model(xsol[4,])

已确认! 我没有尝试通过分析找到这些解决方案,但您可以看到,如果 x[2]x[3] 为零,则 F3F4 为零。然后可以立即找到 x[1]x[4] 的解决方案。