Home > front end >  Efficient way to perform summation to infinite in c
Efficient way to perform summation to infinite in c

Time:03-05

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 ?

CodePudding user response:

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.

CodePudding user response:

Mathematically, summing to infinite is perfectly valid (in some contexts). Formally, the sum you've written is the same as taking the limit of the summation for all k from 1 through n as n tends towards infinite.

Computers, however, cannot compute such a summation via brute force; it would take infinite time to iterate over a loop infinitely many times. Other than taking an approximation, you might be able to find a closed form equation for this sum. Unfortunately, it's not just a simple geometric series, so finding a closed form solution may not be possible, and is almost certainly non-trivial.

  • Related