[R] help about solving two equations

Berend Hasselman bhh at xs4all.nl
Thu Mar 11 07:59:39 CET 2010

Shaoqiong Zhao wrote:
> I have two matrix s1 and s2, each of them is 1000*1.
> and I have two equations:
> digamma(p)-digamma(p+q)=s1,
> digamma(q)-digamma(p+q)=s2,
> and I want to sovle these two equations to get the value of x and y, which
> are also two 1000*1 matrices.

Besides BB there is another package for solving systems of equations:

Use Ravi's definition of your function.
fn <- function(x, s){
   f <- rep(NA, length(x))
   f[1] <- digamma(x[1]) - digamma(x[1]+x[2]) - s[1]
   f[2] <- digamma(x[2]) - digamma(x[1]+x[2]) - s[2]
s <- c(-2,-4)
xstart <- c(1,1)

z1 <- nleqslv(xstart,fn,s=s)

or for more detail 

z2 <- nleqslv(xstart,fn,s=s, control=list(trace=1))

View this message in context: http://n4.nabble.com/help-about-solving-two-equations-tp1588313p1588503.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list