[R] How to solve a non-linear system of equations using R
Moshe Olshansky
m_olshansky at yahoo.com
Wed Jun 4 02:00:18 CEST 2008
Since k_i(l,m,s) are known constants, you actually have a system of four non-linear equations with 4 unknowns.
One possibility is to use optim (check ?optim).
Another one is to use the very recently released package - look at
https://stat.ethz.ch/pipermail/r-help/attachments/20080423/da0b7f6c/attachment.pl
--- On Wed, 4/6/08, Jorge Ivan Velez <jorgeivanvelez at gmail.com> wrote:
> From: Jorge Ivan Velez <jorgeivanvelez at gmail.com>
> Subject: [R] How to solve a non-linear system of equations using R
> To: "R mailing list" <r-help at r-project.org>
> Received: Wednesday, 4 June, 2008, 7:09 AM
> Dear R-list members,
>
> I've had a hard time trying to solve a non-linear
> system (nls) of equations
> which structure for the equation i, i=1,...,4, is as
> follows:
>
>
> f_i(d_1,d_2,d_3,d_4)-k_i(l,m,s) = 0 (1)
>
>
> In the expression above, both f_i and k_i are known
> functions and l, m and s
> are known constants. I would like to estimate the vector
> d=(d_1,d_2,d_3,d_4)
> which is solution of (1). Functions in R to estimate
> f_i-k_i are at the end
> of this message.
>
> Any help/suggestions/comments would be greatly appreciated.
>
> Thanks in advance,
>
> Jorge
>
>
> # ------------------------------
> # Constants
> # ------------------------------
>
> l=1
> m=0.4795
> s=0.4795
>
> # ------------------------------
> # Functions to estimate f_i-k_i
> # ------------------------------
>
> f1=function(d){
> d1=d[1]
> d2=d[2]
> d3=d[3]
> d4=d[4]
> res=2*d1+2*sqrt(2)*d1*d2+2*sqrt(3)*d2*d3+4*d3*d4-l*m*(1+d1^2+d2^2+d3^2+d4^2)
> res
> }
>
> f2=function(d){
> d1=d[1]
> d2=d[2]
> d3=d[3]
> d4=d[4]
> res=2*sqrt(2)*d2+2*d1^2+2*sqrt(6)*d1*d3+4*d2^2+4*sqrt(3)*d2*d4+6*d3^2+8*d4^2-l*(m^2+m^3*s^(-1))*(1+d1^2+d2^2+d3^2+d4^2)
> res
> }
>
> f3=function(d){
> d1=d[1]
> d2=d[2]
> d3=d[3]
> d4=d[4]
> res=6*d1+12*sqrt(2)*d1*d2+18*sqrt(3)*d2*d3+48*d3*d4+2*sqrt(6)*d3+4*sqrt(6)*d1*d4-l*(m^3+3*m^4*s^(-1)+3*m^6*s^(-2))*(1+d1^2+d2^2+d3^2+d4^2)
> res
> }
>
>
> f4=function(d){
> d1=d[1]
> d2=d[2]
> d3=d[3]
> d4=d[4]
> res=12*sqrt(2)*d2+12*d1^2+36*d2^2+72*d3^2+120*d4^2+20*sqrt(6)*d1*d3+56*sqrt(3)*d2*d4+4*sqrt(6)*d4-l*((m^4+6*m^6*s^(-1)+15*m^6*s^(-2)+15*m^7*s^(-3))-3*l^(2)*(m^2+m^3*s^(-1))^2)*(1+d1^2+d2^2+d3^2+d4^2)
> res
> }
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
More information about the R-help
mailing list