Hi friends - I hope this is not a misplaced question. From the literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of Mathematica equations which are solved together to yield over different pH values the concentrations of metabolites in skeletal muscle using the Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a list of equations and V list of variables.? Most of the equations are individual binding reactions of the form 10^6.494*atp*h == hatp and next 10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or K to ATP or creatin for example, but we also have constraints giving total concentrations of say ATP i.e. ATP + ATPH, ATPH2..ATP.Mg I have, without success, tried to find ways to do this in R - I have 36 equations on 36 variables and 8 equations on total concentrations. As far as I can see from the definition of FindRoot in Wolfram, Newton search or secant search is employed. I'm on Windows R 4.2.2 Best wishes Troels Ring, MD Aalborg, Denmark
Hello Troels, As fair as I understand you attempt to numerically solve a system of non linear equations in multiple variables in R. R does not provide this functionality natively, but have you tried multiroot from the rootSolve package: https://cran.r-project.org/web/packages/rootSolve/rootSolve.pdf[1] multiroot is called like multiroot(f, start, ...) where f is a function of one argument which is a vector of n values (representing the n variables) and returning a vector of d values (symbolising the d equations) and start is a vector of length n. E.g. if we want so solve x^2 + y^2 + z^2 = 1 x^3-y^3 = 0 x - z = 0 (which is of course equivalent to x = y = z, x^2 + y^2 + z^2 = 1, so x = y = z = ?sqrt(1/3) ~ 0.577) we?d enter f <- function(x) c(x[1]**2 + x[2]**2 + x[3]**2 - 1, x[1]**3 - x[2]**3, x[1] - x[3]) multiroot(f, c(0,0,0)) which yields $root [1] 0.5773502 0.5773505 0.5773502 $f.root [1] 1.412261e-07 -2.197939e-07 0.000000e+00 $iter [1] 31 $estim.precis [1] 1.2034e-07 Best regards, Valentin Am Donnerstag, 19. J?nner 2023, 10:41:22 CET schrieb Troels Ring:> Hi friends - I hope this is not a misplaced question. From the > literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of > Mathematica equations which are solved together to yield over different > pH values the concentrations of metabolites in skeletal muscle using the > Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a list of > equations and V list of variables. Most of the equations are individual > binding reactions of the form 10^6.494*atp*h == hatp and next > 10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or K > to ATP or creatin for example, but we also have constraints giving total > concentrations of say ATP i.e. ATP + ATPH, ATPH2..ATP.Mg > > I have, without success, tried to find ways to do this in R - I have 36 > equations on 36 variables and 8 equations on total concentrations. As > far as I can see from the definition of FindRoot in Wolfram, Newton > search or secant search is employed. > > I'm on Windows R 4.2.2 > > Best wishes > Troels Ring, MD > Aalborg, Denmark > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-------- [1] https://cran.r-project.org/web/packages/rootSolve/rootSolve.pdf -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part. URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20230119/761f4ff7/attachment.sig>
If you need to solve a nonlinear system of equations you could have a look at the CRAN Task View: Numerical Mathematics: https://cran.r-project.org/view=NumericalMathematics Specifically look in the subsection "Root Finding and Fixed Points". Berend Hasselman> On 19 Jan 2023, at 10:41, Troels Ring <tring at gvdnet.dk> wrote: > > Hi friends - I hope this is not a misplaced question. From the literature (Kushmerick AJP 1997;272:C1739-C1747) I have a series of Mathematica equations which are solved together to yield over different pH values the concentrations of metabolites in skeletal muscle using the Mathematica function FindRoot((E1,E2...),(V2,V2..)] where E is a list of equations and V list of variables. Most of the equations are individual binding reactions of the form 10^6.494*atp*h == hatp and next 10^9.944*hatp*h ==hhatp describing binding of singe protons or Mg or K to ATP or creatin for example, but we also have constraints giving total concentrations of say ATP i.e. ATP + ATPH, ATPH2..ATP.Mg > > I have, without success, tried to find ways to do this in R - I have 36 equations on 36 variables and 8 equations on total concentrations. As far as I can see from the definition of FindRoot in Wolfram, Newton search or secant search is employed. > > I'm on Windows R 4.2.2 > > Best wishes > Troels Ring, MD > Aalborg, Denmark > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
If the equations are in the form shown in your post then take the log of both sides, expand the logs and replace log(whatever) with new variables so now the equations are in linear form and are easy to solve.