Search code examples
c++suminfinite

Efficient way to perform summation to infinite in c++


I am new to c++ and I am trying to implement a function that has a summation between k=1 and infinite:

enter image description here

Do you know how summation to infinite can be implemented efficiently in c++?


Solution

  • Do you know how summation to infinite can be implemented efficiently in c++?

    Nothing of this sort, doing X untill infinity to arrive at any finite result can be done in any language. This is impossible, there is not sugar coated way to say this, but it is how it is for digital computers.

    You can likely however make approximations. Example, a sin x is simply an expression that goes on to infinity. But to compute sin x we don't run the loop till infinity, there will be approximations made saying the terms after these are so small they are within the error bounds. And hence ignored.

    You have to do a similar approach. Assuming t-t1 is always positive, there will come a k where the term (k.pi/2)^2 is so big that 1/e^(...) will be very small, say below 0.00001 and say you want your result to be in an error range of +- 0.001 and so if the series is convergent (look up converging series) then you can likely ignore these terms. Essentially it's a pen and paper problem first that you can then translate to your code.