2

I solve equation sum((2*x+1)/k^x)==3*k (where x belongs to Whole Numbers) as

x=0:10000
y=function(k){sum((2*x+1)/k^x)==3*k}
y(2) 

It returns TRUE.

But I want a method to solve it automatically, how should I solve it?

user227710
  • 3,164
  • 18
  • 35
Hemant Rupani
  • 145
  • 10

1 Answers1

4

you can try function uniroot:

uniroot(function(k){sum((2*x+1)/k^x)-3*k}, c(0,100))$root
#[1] 2.000019

uniroot(function(k){sum((2*x+1)/k^x)-3*k}, c(1,10))$root
#[1] 2

Also in the first call, you don't get exactly 2 probably because of number representation so you may need to add a tolerance; See here for more on the subject.

Community
  • 1
  • 1
Cath
  • 23,906
  • 5
  • 52
  • 86
  • Nice, can I extend x to infinity? – Hemant Rupani Jul 10 '15 at 11:00
  • @HemantRupani to `Inf` you mean ? I don't think so but it may depend on your computer (also, with very large number as "upper bound" for x, it may take a lot of time to compute the root) – Cath Jul 10 '15 at 11:02