[R] Simultaneous equations
Berend Hasselman
bhh at xs4all.nl
Thu Sep 2 22:10:09 CEST 2010
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.
More information about the R-help
mailing list