Re: [R] How to solve following equation?
Thanks for this reply, However I am interested to know why I need to modify my function to a=1? Regards, Gabor Grothendieck wrote: Assume a = 1. If not set b = b/a, etc. Now use (1) uniroot f - function(x) b + c/(1+x) + d/(1+x)^2 - 1 - x uniroot(f, 0:1) $root [1] 0.8392679 $f.root [1] 3.049818e-05 $iter [1] 3 $estim.prec [1] 6.103516e-05 or multiply through by 1+x and subtract 1 from both sides giving x = b + c/(1+x) + d/(1+x)^2 - 1 and iterate that. a - b - c - d - 1 x - 0 for(i in 1:25) { + x - b + c/(1+x) + d/(1+x)^2 - 1 + print(x) + } [1] 2 [1] 0.444 [1] 1.171598 [1] 0.6725419 [1] 0.9553676 [1] 0.7729558 [1] 0.8821595 [1] 0.8135892 [1] 0.8554268 [1] 0.829437 [1] 0.8454056 [1] 0.835527 [1] 0.8416126 [1] 0.837854 [1] 0.8401717 [1] 0.838741 [1] 0.8396236 [1] 0.839079 [1] 0.839415 [1] 0.8392076 [1] 0.8393356 [1] 0.8392566 [1] 0.8393053 [1] 0.8392753 [1] 0.8392938 On Mon, Dec 1, 2008 at 9:47 PM, RON70 [EMAIL PROTECTED] wrote: I need to solve a equation like this : a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3 where a,b,c,d are known constant. Is there any R-way to do that? Thanks in advance -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20785063.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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. -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20817656.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] How to solve following equation?
You don't. This was just to make the presentation simpler. On Wed, Dec 3, 2008 at 12:32 PM, RON70 [EMAIL PROTECTED] wrote: Thanks for this reply, However I am interested to know why I need to modify my function to a=1? Regards, Gabor Grothendieck wrote: Assume a = 1. If not set b = b/a, etc. Now use (1) uniroot f - function(x) b + c/(1+x) + d/(1+x)^2 - 1 - x uniroot(f, 0:1) $root [1] 0.8392679 $f.root [1] 3.049818e-05 $iter [1] 3 $estim.prec [1] 6.103516e-05 or multiply through by 1+x and subtract 1 from both sides giving x = b + c/(1+x) + d/(1+x)^2 - 1 and iterate that. a - b - c - d - 1 x - 0 for(i in 1:25) { + x - b + c/(1+x) + d/(1+x)^2 - 1 + print(x) + } [1] 2 [1] 0.444 [1] 1.171598 [1] 0.6725419 [1] 0.9553676 [1] 0.7729558 [1] 0.8821595 [1] 0.8135892 [1] 0.8554268 [1] 0.829437 [1] 0.8454056 [1] 0.835527 [1] 0.8416126 [1] 0.837854 [1] 0.8401717 [1] 0.838741 [1] 0.8396236 [1] 0.839079 [1] 0.839415 [1] 0.8392076 [1] 0.8393356 [1] 0.8392566 [1] 0.8393053 [1] 0.8392753 [1] 0.8392938 On Mon, Dec 1, 2008 at 9:47 PM, RON70 [EMAIL PROTECTED] wrote: I need to solve a equation like this : a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3 where a,b,c,d are known constant. Is there any R-way to do that? Thanks in advance -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20785063.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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. -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20817656.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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.
Re: [R] How to solve following equation?
I need to solve a equation like this : a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3 where a,b,c,d are known constant. Is there any R-way to do that? Multiplying this expression with (1+x)^3 leads to a polynomial equation. I would certainly recommend the 'PolynomF' package here: # install.packages(PolynomF) library(PolynomF) options(digits=16) x - polynom() a - b - c - d - 1 p - a*(1+x)^3 - b*(1+x)^2 - c*(1+x) - d p # -2 + 2*x^2 + x^3 solve(p) # [1] -1.419643377607080-0.6062907292072i # -1.419643377607080+0.6062907292072i # [3] 0.839286755214161+0.0i The solution x0 = 0.839286755214161 is correct up to the last digit, as can be verified by using a computer algebra system. This also shows that Ryacas is quite exact in this task. Hans Werner Gabor Grothendieck ggrothendieck at gmail.com writes: Assume a = 1. If not set b = b/a, etc. Now use (1) uniroot f - function(x) b + c/(1+x) + d/(1+x)^2 - 1 - x uniroot(f, 0:1) $root [1] 0.8392679 $f.root [1] 3.049818e-05 $iter [1] 3 $estim.prec [1] 6.103516e-05 or multiply through by 1+x and subtract 1 from both sides giving x = b + c/(1+x) + d/(1+x)^2 - 1 and iterate that. a - b - c - d - 1 x - 0 for(i in 1:25) { + x - b + c/(1+x) + d/(1+x)^2 - 1 + print(x) + } [1] 2 [1] 0.444 [1] 1.171598 [1] 0.6725419 [1] 0.9553676 [1] 0.7729558 [1] 0.8821595 [1] 0.8135892 [1] 0.8554268 [1] 0.829437 [1] 0.8454056 [1] 0.835527 [1] 0.8416126 [1] 0.837854 [1] 0.8401717 [1] 0.838741 [1] 0.8396236 [1] 0.839079 [1] 0.839415 [1] 0.8392076 [1] 0.8393356 [1] 0.8392566 [1] 0.8393053 [1] 0.8392753 [1] 0.8392938 On Mon, Dec 1, 2008 at 9:47 PM, RON70 ron_michael70 at yahoo.com wrote: I need to solve a equation like this : a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3 where a,b,c,d are known constant. Is there any R-way to do that? Thanks in advance -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20785063.html Sent from the R help mailing list archive at Nabble.com. __ 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. __ 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. __ R-help@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.
[R] How to solve following equation?
I need to solve a equation like this : a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3 where a,b,c,d are known constant. Is there any R-way to do that? Thanks in advance -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20785063.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] How to solve following equation?
Assume a = 1. If not set b = b/a, etc. Now use (1) uniroot f - function(x) b + c/(1+x) + d/(1+x)^2 - 1 - x uniroot(f, 0:1) $root [1] 0.8392679 $f.root [1] 3.049818e-05 $iter [1] 3 $estim.prec [1] 6.103516e-05 or multiply through by 1+x and subtract 1 from both sides giving x = b + c/(1+x) + d/(1+x)^2 - 1 and iterate that. a - b - c - d - 1 x - 0 for(i in 1:25) { + x - b + c/(1+x) + d/(1+x)^2 - 1 + print(x) + } [1] 2 [1] 0.444 [1] 1.171598 [1] 0.6725419 [1] 0.9553676 [1] 0.7729558 [1] 0.8821595 [1] 0.8135892 [1] 0.8554268 [1] 0.829437 [1] 0.8454056 [1] 0.835527 [1] 0.8416126 [1] 0.837854 [1] 0.8401717 [1] 0.838741 [1] 0.8396236 [1] 0.839079 [1] 0.839415 [1] 0.8392076 [1] 0.8393356 [1] 0.8392566 [1] 0.8393053 [1] 0.8392753 [1] 0.8392938 On Mon, Dec 1, 2008 at 9:47 PM, RON70 [EMAIL PROTECTED] wrote: I need to solve a equation like this : a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3 where a,b,c,d are known constant. Is there any R-way to do that? Thanks in advance -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20785063.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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.
Re: [R] How to solve following equation?
Dear RON70, Another approach would be Ryacas [1]. Take a look at Section 5.3.2: yacas(Newton((1+x)^3-(1+x)^2-(1+x)-1,x,0.1,0.1)) expression(0.839286755214161) Note that this result is _similar_ to Gabor Grothendieck's solution using optim(). HTH, Jorge [1] http://cran.r-project.org/web/packages/Ryacas/index.html On Mon, Dec 1, 2008 at 9:47 PM, RON70 [EMAIL PROTECTED] wrote: I need to solve a equation like this : a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3 where a,b,c,d are known constant. Is there any R-way to do that? Thanks in advance -- View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20785063.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.