Solve the non-linear equation of one variable, but written in the form of summation in "R",

This is a nonlinear equation in

This is a non-linear equation in "mu" that I want to solve numerically using R. All paired (x, y) are known. So the only variable is "mu"

Now I wrote a function in R. Then I try to get the root using the package "rootSolve". But he gives an error.

This is my function code:

f = function(k){
sum(((2*exp(-x) - 1)*(2*exp(-y)- 1))/
    (1 + k*(2*exp(-x) - 1)*(2*exp(-y)- 1)))
}

This is the error after running "uniroot.all" from the "rootSolve" package:

> library(rootSolve)
> uniroot.all(f, interval = c(-1, 1))
numeric(0)
Warning message:
In k * (2 * exp(-x) - 1) :
longer object length is not a multiple of shorter object length

In addition, I am looking for my root in the interval (-1, 1).

Can anybody help? I think my way of defining a function is wrong. Therefore, this error occurs.

Can anyone confirm that my way of defining the function in the picture is correct or not?

Thank you in advance!

Let me add something else:

( , ), (x, y), f(-1) < f(1) and also f(-1) * f(1) < 0. .

, :

R. , curve(f, from = -1, to = 1) Vectorize(f), curve.

- ?

!

+4
1

, uniroot.all . , . uniroot.all .

nleqslv . ( , ):

f <- function(k){
    A <- 2*exp(-x)-1
    B <- 2*exp(-y)-1
    sum((A*B)/(1+k*A*B))
}

set.seed(13)
x <- runif(10)*10
y <- runif(10)*5

:

library(nleqslv)
nleqslv(0,f)

:

$x
[1] 1.42992

$fvec
[1] 2.300633e-09

$termcd
[1] 1

$message
[1] "Function criterion near zero"

$scalex
[1] 1

$nfcnt
[1] 7

$njcnt
[1] 1

$iter
[1] 7

. , testnslv .

** **

uniroot.all , :

fvec <- Vectorize(f)

c(-1,1.7).

+3

Source: https://habr.com/ru/post/1678799/


All Articles