What are the stages and times of the rocket's flight?

  • Context: Comp Sci 
  • Thread starter Thread starter Lord Dark
  • Start date Start date
  • Tags Tags
    C++ Rockets
Click For Summary

Discussion Overview

The discussion revolves around programming challenges related to analyzing rocket flight data stored in a file. Participants are focused on determining specific stages of a rocket's flight based on its velocity and acceleration, as well as identifying times when the acceleration is solely due to gravity.

Discussion Character

  • Technical explanation
  • Homework-related
  • Mathematical reasoning

Main Points Raised

  • One participant describes the requirements for a program that reads rocket flight data and identifies stages based on velocity and acceleration.
  • Another participant suggests recording the time when acceleration transitions from negative to positive as a method to determine stage firing times.
  • A different participant proposes two methods for implementing this: using a variable to track the sign of the last acceleration value or comparing neighboring values in the data set.
  • Concerns are raised about the reliability of the second method if acceleration values reach zero.
  • One participant expresses confusion about how to implement the suggested methods in their code.
  • A later reply indicates that the participant has successfully resolved their issue with the help of the suggestions provided.

Areas of Agreement / Disagreement

Participants generally agree on the approach to determine when the rocket stages fire based on acceleration changes, but there are differing opinions on the best coding implementation. The discussion remains unresolved regarding the most reliable method to track acceleration transitions.

Contextual Notes

Participants discuss specific programming logic and potential pitfalls in their approaches, such as handling zero values in acceleration. There are also references to specific data file formats and expected output, which may limit the generalizability of the solutions discussed.

Who May Find This Useful

Individuals interested in programming, data analysis, and rocket flight dynamics may find this discussion relevant, particularly those working on similar coding challenges or studying related physics concepts.

Lord Dark
Messages
120
Reaction score
0
Hi guys,

I've got the following question :

Assume that there is an information stored in a file named rocket3.dat and that each line
contains four values: time, altitude, velocity, and acceleration. Assume that the units are s, m, m/s, and m/s2
respectively.
(A new stage in the rocket life can be determined when the velocity increases to some peak and then begins decreasing. After each stage of the rocket is fired, the acceleration will initially increase and then decrease to -9.8 m/s2, which is downward acceleration due to gravity.)

and he want's me to :
Write a program that does each of the followings:
1. Reads the data file rocket3.dat
2. Generate a new output file output.dat and write the output of this program to this file
3. Determine the time that corresponds to the firing of each stage if any.
4. Find the times of the rocket flight during which acceleration is due only to gravity. Allow the acceleration to range within 5% of the value of gravity; if we assume that the gravity is -9.8 m/s2, then the range of acceleration of interest is between -10.29 m/s2 and -9.31 m/s2.

I wrote the following code :
/*


The following program ...

*/

#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;

int main ()
{
double t, // declaring the time
al, // declaring the altitude
v, // declaring the velocity
a, // declaring the acceleration
min_v(9e3), // declaring the minimum velocity
min_a(9e2);
ifstream infile ; infile.open("rocket3.dat"); // declaring the data file and it's address
ofstream outfile ; outfile.open("output.txt") ; // declaring the file which our results will be in
if (infile.fail())
{
count << "There is no file named rocket3 the program will terminate" << endl ;
return (-1);
}
outfile << showpoint << fixed << scientific ;
infile >> t >> al >> v >> a ;
while (infile)
{
if (v < min_v)
min_v = v ;
if (a < min_a && a > 0)
min_a = a ;

if (a > -10.29 && a < -9.31)
{
outfile << "Acceleration due to gravity only at time: " << t << endl ;
}

infile >> t >> al >> v >> a ;
}
if (v == min_v && a == min_a )
outfile << "Stage fired at " << t << endl ;

return 0;
}

I've solved part 1,2,4 .. but the problem is in part 3 which I don't understand what the question means (I tried by maximum and minimum the velocity and acceleration but I get the first time which is wrong ... now I need your help guys :)
I've uploaded the data files (rocket3.txt) and the final results (how it should be)
 

Attachments

  • Output.jpg
    Output.jpg
    74.1 KB · Views: 551
  • rocket3.txt
    rocket3.txt
    1.5 KB · Views: 459
Last edited:
Physics news on Phys.org
guys I've got an idea but I don't know how to do it ,,

I want to say when the acceleration goes from negative to positive record the time ,, but how can I say that in codes ??
 
Either remember sign of the last value in additional variable and go for (lastsignnegative && a > 0), or read all in the table and compare signs of neighboring values by something like (a < 0 && a[i+1] > 0). This is not bulletproof as if at some point a is zero you will probably miss it.
 
thanks Borek, but I don't know how to assign (lastsignnegative) to the last negative value and in the second way how to assign it in my code ?? i mean how to assign it to values of a if a is the acceleration and you've typed a(i) write it as a(a) ??
 
Last edited:
thanks borek ,, I've got you now :) ,, solved :D thanks again
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K