Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all,

I would like to write a formula consist of summation.

G(i) = m + sigma (j=0 to i-1) G(j) * m

in each level to calculate new G we have to use previous calculated Gs. for example:
for G(3) we need (G(0)*m + G(1)*m + G(2)*m) which have calculated in previous levels. And m is a constant(18.01).

I would like to write a code for this loop (data numbers come from a column in a text file) But as I am beginner to python I dont know how to start. Do I have to use more than one loop? a loop for G(i) and a loop for sigma? what can be the exact form?

Thank you in advance for your help


What I have tried:

I tried simple codes for summation but I have no idea for this problem. 
Posted
Updated 22-Oct-21 6:46am

1 solution

Use a list to store each value of G, and a loop index to get the previous values. See 3. An Informal Introduction to Python — Python 3.9.7 documentation[^]. Or maybe better to start at The Python Tutorial — Python 3.9.7 documentation[^].
 
Share this answer
 
Comments
mohammad rezayani 22-Oct-21 12:47pm    
Dear Richard

Thank you very much for your answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900