15,119,363 members

Copy Code

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

Copy Code

I tried simple codes for summation but I have no idea for this problem.

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[^].

Comments

Dear Richard

Thank you very much for your answer

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