Using previous values of a loop for the next loop











up vote
0
down vote

favorite












I'm very very new to coding and I'm currently trying to make a model of a rocket flight. In the model in need to calculate the rocket's speed but therefore I need to know the air resistance which is determined by the speed of the rocket. So my problem is that I'm trying to calculate a value for which I need the value itself. My solution to the problem was to take the previous value of the speed to determine the air resistance and calculate the new speed. I need to do the same for my h (Height)



Velocity = (( F_Rocket - ( F_Drag + F_Gravity ) / m ) t.



This is the formula that I'm using to calculate the speed, I derived it from



F_resulting = F_Rocket - (F_Drag + F_Gravity)



T0 = 288.15 #temperature needed for the air density
q1 = -0.0065 #constant
e = 2.718281828459
p0 = 101325 #base pressure
g = 9.80665 # gravity
R = 287.00 # gas constant
G = 6.67259 * (10 ** -11) # gravity constant
m1 = 5.972 * (10 ** 24) #mass earth
m2 = 0.070 #mass rocket (mini plastic rocket)
rAarde = 6371000 #radius earth
Cw = 0.14
A = 0.00053913
F_Rocket = 0.22
t = 0 # this is time

while t <= 50: #the while loop is expressed in time
T1 = T0 + q1 * (h - h0)
print('T1 = ', T1, 'K')
p1 = p0 * ((T1 / T0) ** ( -g / (q1 * R)))
rho1 = p1 / (R * T1)
F_Drag = 0.5 * A * Cw * rho1 * (v_old ** 2) # This v needs to be one from the previous loop, I will also need some starting point
v_new = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
h_new = v_old * t
F_Gravity = G * ((m1 * m2) / (rAarde + h_old))
print(Drag1, 'N')
print(rho1, 'Kg m^-3')
print(p1, 'pa')
t += 1;


I just need to get the values of previous answers like in a recursive formula. If someone could explain me how to get that coded, that would be great.










share|improve this question









New contributor




philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I'm very very new to coding and I'm currently trying to make a model of a rocket flight. In the model in need to calculate the rocket's speed but therefore I need to know the air resistance which is determined by the speed of the rocket. So my problem is that I'm trying to calculate a value for which I need the value itself. My solution to the problem was to take the previous value of the speed to determine the air resistance and calculate the new speed. I need to do the same for my h (Height)



    Velocity = (( F_Rocket - ( F_Drag + F_Gravity ) / m ) t.



    This is the formula that I'm using to calculate the speed, I derived it from



    F_resulting = F_Rocket - (F_Drag + F_Gravity)



    T0 = 288.15 #temperature needed for the air density
    q1 = -0.0065 #constant
    e = 2.718281828459
    p0 = 101325 #base pressure
    g = 9.80665 # gravity
    R = 287.00 # gas constant
    G = 6.67259 * (10 ** -11) # gravity constant
    m1 = 5.972 * (10 ** 24) #mass earth
    m2 = 0.070 #mass rocket (mini plastic rocket)
    rAarde = 6371000 #radius earth
    Cw = 0.14
    A = 0.00053913
    F_Rocket = 0.22
    t = 0 # this is time

    while t <= 50: #the while loop is expressed in time
    T1 = T0 + q1 * (h - h0)
    print('T1 = ', T1, 'K')
    p1 = p0 * ((T1 / T0) ** ( -g / (q1 * R)))
    rho1 = p1 / (R * T1)
    F_Drag = 0.5 * A * Cw * rho1 * (v_old ** 2) # This v needs to be one from the previous loop, I will also need some starting point
    v_new = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
    h_new = v_old * t
    F_Gravity = G * ((m1 * m2) / (rAarde + h_old))
    print(Drag1, 'N')
    print(rho1, 'Kg m^-3')
    print(p1, 'pa')
    t += 1;


    I just need to get the values of previous answers like in a recursive formula. If someone could explain me how to get that coded, that would be great.










    share|improve this question









    New contributor




    philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm very very new to coding and I'm currently trying to make a model of a rocket flight. In the model in need to calculate the rocket's speed but therefore I need to know the air resistance which is determined by the speed of the rocket. So my problem is that I'm trying to calculate a value for which I need the value itself. My solution to the problem was to take the previous value of the speed to determine the air resistance and calculate the new speed. I need to do the same for my h (Height)



      Velocity = (( F_Rocket - ( F_Drag + F_Gravity ) / m ) t.



      This is the formula that I'm using to calculate the speed, I derived it from



      F_resulting = F_Rocket - (F_Drag + F_Gravity)



      T0 = 288.15 #temperature needed for the air density
      q1 = -0.0065 #constant
      e = 2.718281828459
      p0 = 101325 #base pressure
      g = 9.80665 # gravity
      R = 287.00 # gas constant
      G = 6.67259 * (10 ** -11) # gravity constant
      m1 = 5.972 * (10 ** 24) #mass earth
      m2 = 0.070 #mass rocket (mini plastic rocket)
      rAarde = 6371000 #radius earth
      Cw = 0.14
      A = 0.00053913
      F_Rocket = 0.22
      t = 0 # this is time

      while t <= 50: #the while loop is expressed in time
      T1 = T0 + q1 * (h - h0)
      print('T1 = ', T1, 'K')
      p1 = p0 * ((T1 / T0) ** ( -g / (q1 * R)))
      rho1 = p1 / (R * T1)
      F_Drag = 0.5 * A * Cw * rho1 * (v_old ** 2) # This v needs to be one from the previous loop, I will also need some starting point
      v_new = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
      h_new = v_old * t
      F_Gravity = G * ((m1 * m2) / (rAarde + h_old))
      print(Drag1, 'N')
      print(rho1, 'Kg m^-3')
      print(p1, 'pa')
      t += 1;


      I just need to get the values of previous answers like in a recursive formula. If someone could explain me how to get that coded, that would be great.










      share|improve this question









      New contributor




      philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I'm very very new to coding and I'm currently trying to make a model of a rocket flight. In the model in need to calculate the rocket's speed but therefore I need to know the air resistance which is determined by the speed of the rocket. So my problem is that I'm trying to calculate a value for which I need the value itself. My solution to the problem was to take the previous value of the speed to determine the air resistance and calculate the new speed. I need to do the same for my h (Height)



      Velocity = (( F_Rocket - ( F_Drag + F_Gravity ) / m ) t.



      This is the formula that I'm using to calculate the speed, I derived it from



      F_resulting = F_Rocket - (F_Drag + F_Gravity)



      T0 = 288.15 #temperature needed for the air density
      q1 = -0.0065 #constant
      e = 2.718281828459
      p0 = 101325 #base pressure
      g = 9.80665 # gravity
      R = 287.00 # gas constant
      G = 6.67259 * (10 ** -11) # gravity constant
      m1 = 5.972 * (10 ** 24) #mass earth
      m2 = 0.070 #mass rocket (mini plastic rocket)
      rAarde = 6371000 #radius earth
      Cw = 0.14
      A = 0.00053913
      F_Rocket = 0.22
      t = 0 # this is time

      while t <= 50: #the while loop is expressed in time
      T1 = T0 + q1 * (h - h0)
      print('T1 = ', T1, 'K')
      p1 = p0 * ((T1 / T0) ** ( -g / (q1 * R)))
      rho1 = p1 / (R * T1)
      F_Drag = 0.5 * A * Cw * rho1 * (v_old ** 2) # This v needs to be one from the previous loop, I will also need some starting point
      v_new = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
      h_new = v_old * t
      F_Gravity = G * ((m1 * m2) / (rAarde + h_old))
      print(Drag1, 'N')
      print(rho1, 'Kg m^-3')
      print(p1, 'pa')
      t += 1;


      I just need to get the values of previous answers like in a recursive formula. If someone could explain me how to get that coded, that would be great.







      python






      share|improve this question









      New contributor




      philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 21 at 19:48









      dustinos3

      335216




      335216






      New contributor




      philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 21 at 18:31









      philip geheim

      1




      1




      New contributor




      philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      philip geheim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Initialize a velocity variable (vel) outside of the while loop. Update it to the new value only after calculating F_Drag



          vel = 0   # pick an appropriate starting value

          while t <= 50:
          ....
          F_Drag = 0.5 * A * Cw * rho1 * (vel ** 2)
          vel = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
          ....


          Now every time you go into the loop vel will be the previously calculated value for F_Drag, then you update it using the F_Rocket equation.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });






            philip geheim is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418463%2fusing-previous-values-of-a-loop-for-the-next-loop%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Initialize a velocity variable (vel) outside of the while loop. Update it to the new value only after calculating F_Drag



            vel = 0   # pick an appropriate starting value

            while t <= 50:
            ....
            F_Drag = 0.5 * A * Cw * rho1 * (vel ** 2)
            vel = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
            ....


            Now every time you go into the loop vel will be the previously calculated value for F_Drag, then you update it using the F_Rocket equation.






            share|improve this answer

























              up vote
              0
              down vote













              Initialize a velocity variable (vel) outside of the while loop. Update it to the new value only after calculating F_Drag



              vel = 0   # pick an appropriate starting value

              while t <= 50:
              ....
              F_Drag = 0.5 * A * Cw * rho1 * (vel ** 2)
              vel = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
              ....


              Now every time you go into the loop vel will be the previously calculated value for F_Drag, then you update it using the F_Rocket equation.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Initialize a velocity variable (vel) outside of the while loop. Update it to the new value only after calculating F_Drag



                vel = 0   # pick an appropriate starting value

                while t <= 50:
                ....
                F_Drag = 0.5 * A * Cw * rho1 * (vel ** 2)
                vel = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
                ....


                Now every time you go into the loop vel will be the previously calculated value for F_Drag, then you update it using the F_Rocket equation.






                share|improve this answer












                Initialize a velocity variable (vel) outside of the while loop. Update it to the new value only after calculating F_Drag



                vel = 0   # pick an appropriate starting value

                while t <= 50:
                ....
                F_Drag = 0.5 * A * Cw * rho1 * (vel ** 2)
                vel = ((F_Rocket - (F_Drag + F_Gravity) / m) * t
                ....


                Now every time you go into the loop vel will be the previously calculated value for F_Drag, then you update it using the F_Rocket equation.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 at 18:47









                Bill S.

                816




                816






















                    philip geheim is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    philip geheim is a new contributor. Be nice, and check out our Code of Conduct.













                    philip geheim is a new contributor. Be nice, and check out our Code of Conduct.












                    philip geheim is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418463%2fusing-previous-values-of-a-loop-for-the-next-loop%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                    How to ignore python UserWarning in pytest?

                    Alexandru Averescu