Need Help Starting Code

So I'm having some trouble planning out how to tackle this problem:
A toy rocket is powered by pressurized water that is discharged from the nozzle at the beginning of the flight.
a. Plot the elevation as a function of time
b. Compute and plot the velocity and acceleration of the rocket as functions of time
c. Write a MATLAB code that will automatically determine the thruster time, the maximum altitude, the maximum velocity, and the maximum acceleration
d. The tip of the rocket transports a 2.7 gram ping-pong ball. Determine the maximum support force for the ball.
I am given data: time (in seconds) and elevation (in meters). My first problem lies in the fact that I have a TON of data. 61 pages worth of data. 2 columns and 3280 rows of data. I know I'll need to preallocate this somehow to make it run efficiently. What help/tips do you have to help me get started and to help me make it run most efficiently?
EDIT: I have m=zeros(3280,2) as my preallocation. I am considering putting the data into a file and trying to pull it, to save space.
UPDATE 1:
rTimeData=fopen('rocket_time_data.txt','r');
formatSpec = '%f';
A = fscanf(rTimeData,formatSpec);
fclose(rTimeData);
rElevData=fopen('rocket_elev_data.txt','r');
formatSpec = '%f';
B=fscanf(rElevData,formatSpec);
fclose(rElevData);
%PART B
vel=sqrt(0^2+2*(9.81)*(B-0));
acc=vel/B;
My acceleration seems to not be right. Should it be a 3280x3280? (Part A plots fine, by the way.)

5 Commenti

Jan
Jan il 23 Giu 2018
This looks like a homework question. Then please post your current code and ask a specific question about it. Do not start with improving the efficiency of the code. If you program it poorly, it will need 0.3 seconds to run, while a professional code needs 0.15 seconds only - but who cares?
I do not know what "pull a file" means. Working on the hard disk is very slow, so try to solve the problem completely in the memory at first.
dpb
dpb il 23 Giu 2018
Modificato: dpb il 23 Giu 2018
" I am considering putting the data into a file ..."
That would be the first step; surely this was collected and is already in electronic form somewhere, not just on paper? If not, hopefully the quality is good enough an OCR can interpret it without too many errors. Otherwise, the biggest job in this assignment will be to simply type the data into a file for starters.
Once that's done look at the tutorial information in "Getting Started" on reading input files and graphics. a) and b) will be straightforward from the given data.
It appears the c) part is going to be lacking some critical information if this is the entire problem statement as there is no description of the rocket itself that would need to be able to solve equations of motion to match the data; there would be an infinite number of possible solutions.
Amplification of Jan's point -- while it seems like a lot of data on paper, 3280 samples of time and elevation is only
3280*2*8 = 52480 bytes
That's not enough to been seen in today's environment so you need not concern yourself at all with memory issues for this problem.
dpb
dpb il 24 Giu 2018
What's the units of the elevation data?
If you have distance and time, what's definition of velocity?
Image Analyst
Image Analyst il 24 Giu 2018
2 columns and 3280 rows of data is a microscopic amount of data, NOT "a TON of data". For example, it's like only one two-thousandths (0.05%) the amount of data in an ordinary digital image. It will easily all fit into your computer memory simultaneously.
For what it's worth, I'm attaching my demo of a projectile/trajectory. It computes just about anything one would ever want to know about a projectile.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Richiesto:

il 23 Giu 2018

Commentato:

il 24 Giu 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by