Dear R experts
I'm trying to use R to solve for the root of one nonlinear function I
tried to use the package "rootSolve" but it didn't give any value
the
value is (numeric(0)) although I tried on changing the interval of
root.
I tried also the package "nleqslv" but itdidn't iterate what ever
the
guess I'm giving to the root.
please tell me what to do? should i have to use another package or search
in another program rather than R (like matehmatica or matlab for
example)
Here's the r code I've used
>>>>>>>>>>>>>
alpha <- 40
beta <- 10
n <- 20
to1 <- c(0.26308002, 0.09350968, 0.17371400,
0.10310227,0.15631892,0.21255328,0.12333682,0.076527274)
to2
<-(0.31238764,0.03546888,0.41671089,0.15223569,0.68194715,0.01491989,0.37137511,0.19945158,0.23525854,0.29444296)
tc <- c(0,0,0.06469491,0.20090405)
to1 <- matrix(to1)
to2 <- matrix(to2);
tc <- matrix(tc)
r1 <- nrow(to1)
r2 <- nrow(to2)
I <- ifelse((tc>0), 1, 0)
fn <- function(a) sum(sapply(2:4, function(j1) {
sum(sapply(2:(j1-1),
function(j2){
factorial(n-r2-I[j1]-I[j2])*factorial(r2+I[j1]+I[j2])*(j1>j2)/(((beta+sum(to1)+sum(tc)-tc[j1]-tc[j2])^(r1+alpha))*((beta+sum(to2)+tc[j1]+tc[j2])^(r2+alpha)))}))}))-sum(sapply(2:4,
function(j1) {sum(sapply(2:(j1-1),
function(j2){factorial(n+1-r2-I[j1]-I[j2])*factorial(r2+I[j1]+I[j2])*(j1>j2)/((n+2)*((a+beta+sum(to1)+sum(tc)-tc[j1]-tc[j2])^(r1+alpha))*((beta+sum(to2)+tc[j1]+tc[j2])^(r2+alpha)))}))}))-sum(sapply(2:4,
function(j1) {sum(sapply(2:(j1-1),
function(j2){factorial(n-r2-I[j1]-I[j2])*factorial(1+r2+I[j1]+I[j2])*(j1>j2)/((n+2)*((beta+sum(to1)+sum(tc)-tc[j1]-tc[j2])^(r1+alpha))*((a+beta+sum(to2)+tc[j1]+tc[j2])^(r2+alpha)))}))}))
library(rootSolve)
a=uniroot.all(fn,c(0,3))
##"a" is : numeric(0)
library(nleqslv)
nleqslv(5, fn) >>>>>>>>>>
what ever the value i put for the guess appears as the solution of the root
and the message is "Function criterion near zero"
Thank you