Dear all, I am relatively new to R and have had some difficulty in understanding the user manual for a package that I have downloaded to evaluate non-linear simultaneous equations. The package is called systemfit. Does anyone have any experience of this package? What I am trying to do is solve a non linear simultaneous equations... Could anyone give me an example (please) of the code that would be needed to return solutions for the following system using systemfit (or any other better package): y=1/x y=sin(x) within a range of say x=-10 to 10 (x in radians) Thanks, I really appreciate your help in advance. Ben -- View this message in context: http://r.789695.n4.nabble.com/Simultaneous-equations-tp2524645p2524645.html Sent from the R help mailing list archive at Nabble.com.
benhartley903 wrote:> > Dear all, > I am relatively new to R and have had some difficulty in understanding the > user manual for a package that I have downloaded to evaluate non-linear > simultaneous equations. > The package is called systemfit. > Does anyone have any experience of this package? > What I am trying to do is solve a non linear simultaneous equations... > > Could anyone give me an example (please) of the code that would be needed > to return solutions for the following system using systemfit (or any other > better package): > > y=1/x > y=sin(x) > > within a range of say x=-10 to 10 (x in radians) > > Thanks, I really appreciate your help in advance. > > Ben >systemfit is intended for estimating a system of simultaneous equations. You seem to want to solve a system. I assume you want to solve this system for x and y. You could use package nleqslv as follows: library(nleqslv) fun <- function(x) { f <- numeric(length(x)) f[1] <- x[2] - 1/x[1] f[2] <- x[2] - sin(x[1]) f } x.start <- c(1,1) nleqslv(x.start,fun) # will give 1.1141571 0.8975395 x.start <- c(2,2) nleqslv(x.start,fun) # will give 2.7726047 0.3606717 Berend -- View this message in context: http://r.789695.n4.nabble.com/Simultaneous-equations-tp2524645p2524710.html Sent from the R help mailing list archive at Nabble.com.
On 09/02/2010 09:25 PM, benhartley903 wrote:> > Dear all, > I am relatively new to R and have had some difficulty in understanding the > user manual for a package that I have downloaded to evaluate non-linear > simultaneous equations. > The package is called systemfit. > Does anyone have any experience of this package? > What I am trying to do is solve a non linear simultaneous equations... > > Could anyone give me an example (please) of the code that would be needed to > return solutions for the following system using systemfit (or any other > better package): > > y=1/x > y=sin(x) > > within a range of say x=-10 to 10 (x in radians) > > Thanks, I really appreciate your help in advance. > > BenSystemfit is not even in the same ballpark...! I'd just rewrite the above as x * sin(x) - 1 = 0 make a graph to bracket the roots and then use uniroot.> f <- function(x) x*sin(x)-1 > curve(f, interval=c(-10.10) > f(c(0,2,5,7,10))[1] -1.0000000 0.8185949 -5.7946214 3.5989062 -6.4402111 So the roots are> uniroot(f,interval=c(7,10))$root[1] 9.317241> uniroot(f,interval=c(5,7))$root[1] 6.43914> uniroot(f,interval=c(2,5))$root[1] 2.772631> uniroot(f,interval=c(0,2))$root[1] 1.114161 and 4 more symmetrically below zero. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
Thanks Peter Actually I should have specified. These are not actually the functions I ultimately want to solve can't be rearranged explicitly and substituted. I do need a way to solve simultaneously. Ben -- View this message in context: http://r.789695.n4.nabble.com/Simultaneous-equations-tp2524645p2524751.html Sent from the R help mailing list archive at Nabble.com.