Hemant Rupani
Hemant Rupani

Reputation: 155

How to solve equation having summation?

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?

Upvotes: 2

Views: 1413

Answers (1)

Cath
Cath

Reputation: 24074

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.

Upvotes: 4

Related Questions