我正在尝试求解非线性方程组。问题是终止代码返回(3),这意味着“找不到更好的解决方案”。我想知道是否应该使用某些选项来获得解决方案,或者我应该搜索具有相同目标的其他软件包还是什么? 这是代码:
library(nleqslv) ## solving nonlinear equations
mu.initial=c(0.04732269,0.77871236)
R.bar=0.7801489
R2.bar=0.2877999
fun=function(z){
v=z^2
q=numeric(length(v))
q[1]=(exp(-(v[1]^2)/(2*(v[2]))))*((v[1]/sqrt(v[2]))+
(((v[1]/sqrt(v[2]))^3)*factorial(3)/((factorial(1))^2*(factorial(2))*
(2^3)))+
(((v[1]/sqrt(v[2]))^5)*factorial(5)/((factorial(2))^2*(factorial(3))*
(2^6)))+
(((v[1]/sqrt(v[2]))^7)*factorial(7)/((factorial(3))^2*(factorial(4))*
(2^9)))+
(((v[1]/sqrt(v[2]))^9)*factorial(9)/((factorial(4))^2*(factorial(5))*
(2^12)))+
(((v[1]/sqrt(v[2]))^11)*factorial(11)/((factorial(5))^2*(factorial(6))*
(2^15))))-(4*R.bar/sqrt(2*pi))
q[2]=(exp(-(v[1]^2)/(2*(v[2]))))*((0.25*(((v[1]/sqrt(v[2]))^2)+
(((v[1]/sqrt(v[2]))^4)*0.5)+
(((v[1]/sqrt(v[2]))^6)*0.1172)+(((v[1]/sqrt(v[2]))^8)*0.01822)+
(((v[1]/sqrt(v[2]))^10)*0.0021)+
(((v[1]/sqrt(v[2]))^12)*0.0002)))+4*(((v[1]/sqrt(v[2]))^4)*(-0.0104+0.00146*
((v[1]/sqrt(v[2]))^2)-0.00016*((v[1]/sqrt(v[2]))^4)+0.000014*
((v[1]/sqrt(v[2]))^6))+
((0.5)*(v[1]/sqrt(v[2]))^6)*(-0.039+0.0055*((v[1]/sqrt(v[2]))^2)-0.00061*
((v[1]/sqrt(v[2]))^4)+0.000055*((v[1]/sqrt(v[2]))^6))+
((1/8)*(v[1]/sqrt(v[2]))^8)*(-0.1458+0.0205*((v[1]/sqrt(v[2]))^2)-0.0023*
((v[1]/sqrt(v[2]))^4)+0.000212*((v[1]/sqrt(v[2]))^6))+
((1/48)*(v[1]/sqrt(v[2]))^10)*(-0.5468+0.0773*((v[1]/sqrt(v[2]))^2)-0.00728*
((v[1]/sqrt(v[2]))^4)+0.0008*((v[1]/sqrt(v[2]))^6))+
((1/384)*(v[1]/sqrt(v[2]))^12)*(-2.0625+0.2932*((v[1]/sqrt(v[2]))^2)-0.0332*
((v[1]/sqrt(v[2]))^4)+0.00309*((v[1]/sqrt(v[2]))^6))+
((1/3840)*(v[1]/sqrt(v[2]))^14)*(-7.82+1.117*((v[1]/sqrt(v[2]))^2)-0.1271*
((v[1]/sqrt(v[2]))^4)+0.01186*((v[1]/sqrt(v[2]))^6))))-R2.bar
q
}
sd=sqrt(0.9537661)
half.k=sqrt(0.7801489)
v.start=c(half.k,sd)
ss1=nleqslv(v.start,fun,method="Broyden",global="qline",control=list(cndtol=10^-12,maxit=1000,allowSingular =TRUE))