I am writing my masters thesis and I got stuck with this problem in my R code. Mathematically, I want to solve this system of non-linear equations with the R-package “nleqsl
I am the author of nleqslv and I'm quite suprised at how you are using it. As mentioned by others you are not returning anything sensible.
y1 should be y[1] and y2 should be y[2]. If you want us to say sensible things you will have to provide numerical values for D1, R, T, sigmaS and SO1. I have tried this:
T <- 1; D1 <- 1000; R <- 0.01; sigmaS <- .1; SO1 <- 1000
These have been entered before the function definition. See this
library(nleqslv)
T <- 1
D1 <- 1000
R <- 0.01
sigmaS <- .1
SO1 <- 1000
fnewton <- function(x){
y <- numeric(2)
d1 <- (log(x[1]/D1)+(R+x[2]^2/2)*T)/x[2]*sqrt(T)
d2 <- d1-x[2]*sqrt(T)
y[1] <- SO1 - (x[1]*pnorm(d1) - exp(-R*T)*D1*pnorm(d2))
y[2] <- sigmaS*SO1 - pnorm(d1)*x[2]*x[1]
y
}
xstart <- c(21623379, 0.526177094846878)
nleqslv
has no problem in finding a solution in this case. Solution found is : c(1990.04983,0.05025)
. There appears to be no need to set the btol
parameter and you can use method Broyden
.