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.
python
New contributor
add a comment |
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.
python
New contributor
add a comment |
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.
python
New contributor
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
python
New contributor
New contributor
edited Nov 21 at 19:48
dustinos3
335216
335216
New contributor
asked Nov 21 at 18:31
philip geheim
1
1
New contributor
New contributor
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 21 at 18:47
Bill S.
816
816
add a comment |
add a comment |
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.
philip geheim is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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