[R] How to solve a non-linear system of equations using R

ctu at bigred.unl.edu ctu at bigred.unl.edu
Tue Jun 3 23:22:37 CEST 2008


Hi Jorge,

Have you tried to use "systemfit" package. In this package, this is a  
function call " nlsystemfit ". This might help.

Chunhao



Quoting Jorge Ivan Velez <jorgeivanvelez at gmail.com>:

> 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