求解非线性方程组 [英] Solve system of non-linear equations

查看:48
本文介绍了求解非线性方程组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to solve the following system of four equations. I have tried using the "rootSolve" package but it does not seem like I can find a solution this way.

我使用的代码如下:

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

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

I have changed the starting values, as suggested in another similar answer, and for some I can find a solution. However, this system - according to the source I am using - should have an uniquely identified solution. Any idea about how to solve this system?

谢谢!

推荐答案

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

Your system of equations has multiple solutions. I use a different package to solve your system: nleqslv as follows:

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 的答案相同的解决方案.

This gets the same solution as the answer of Prem.

然而,您的系统有多种解决方案.包 nleqslv 提供了一个函数来搜索给定不同起始值矩阵的解决方案.你可以用这个

Your system however has multiple solutions. Package nleqslv provides a function to search for solutions given a matrix of different starting values. You can use this

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

(注意:不同的种子可能无法找到所有四种解)

(Note: different seeds may not find all four solutions)

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

You will see that there are four different solutions:

$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
.......

这清楚地表明精确解如以下矩阵中给出的

This clearly suggests that the exact solutions are as given in the following matrix

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] 的解.

Confirmed! I have not tried to find these solutions analytically but you can see that if x[2] and x[3] are zero then F3 and F4 are zero. The solutions for x[1] and x[4] can then be immediately found.

这篇关于求解非线性方程组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆