Matlab loops help (with physics)

11 views (last 30 days)
Gerald Melins
Gerald Melins on 30 Mar 2015
Commented: James Tursa on 31 Mar 2015
A skydiver with a mass of 80 kg (including parachute) jumps out of an airplane at an altitude of 4000 m, the initial vertical velocity is 0 m/s. He free-falls for 40 seconds before opening a parachute. The parachute has a 10 m diameter when completely opened (you can assume it opens instantaneously). Create a program in MATLAB that calculates and plots the skydiver’s vertical speed and altitude as a function of time using the following equations and values. Remember that the skydiver cannot exceed the terminal velocity and the parachute has a failsafe to open at 1000 m.
Hints: There are different terminal velocities with and without the parachute open, assume that the parachute opens instantaneously.
Constant values g = 9.81 [m/s^2 ] (Gravitational Acceleration) p_air = 1.225 [kg/m^3 ] (Density of air)
Before Opening: A = 0.5 [m^2 ] Cd = 0.7
After Opening: A = pi/4 * D^2 [m2 ] Cd = 1.4
Calculation of Terminal Velocity
Vt=0.99*sqrt((2*mass*gravity)/(p_air*A*Cd))
Calculation of Downward Acceleration (derived from F=m*a)
ai=(1/2)*(p_air/mass)*(V^2_i-1)*(A)*(Cd)-g
Kinematics Equations Setup for a loop
Vi=Vi-1+ai*(delta t) t is time
Yi=Yi-1+Vi-1*(delta t)+(1/2)*ai*(delta t)
Setup the diameter of the parachute, initial altitude, time of opening the parachute, and the time step as user inputs.
In addition to the plots, output the answers to the following questions the command window: 1. Is terminal velocity reached before the skydiver opens the parachute? If so, at what time did the skydiver reach terminal velocity? 2. At what altitude did the parachute open? 3. Does the skydiver open the parachute or did the failsafe mechanism open it?
Use While-end loops to solve for the equations, must use these
  6 Comments
Gerald Melins
Gerald Melins on 30 Mar 2015
I also got this error Attempted to access V(0); index must be a positive integer or logical.

Sign in to comment.

Answers (1)

James Tursa
James Tursa on 30 Mar 2015
Edited: James Tursa on 30 Mar 2015
OK, now we have something to work with. Thanks for making the coding attempt and posting it.
My suggestion is to first simplify this to a test case that you can compare with the exact solution for the constant acceleration case. To do that, get rid of all the complicated parachute & drag stuff and while loop conditions and do the simple constant acceleration free fall (copy your code to a new file name first) for a fixed number of steps. E.g., simply extracting parts of your above code for a simple free-fall simulation:
% Constants
g=-9.81; % m/s^2
% Initial conditions
a(1) = g; % m/s^2
V(1) = 0; % m/s
Y(1) = 4000; % m
% Simulation step size
delta_t = 0.25; % s
% Initial time
t = 0; % s
% Simulation
for i=2:41 % start at i=2, not i=1
a(i) = -g; % Constant down acceleration
V(i) = V(i-1) + a(i) * delta_t; % Update velocity
Y(i) = Y(i-1) + V(i-1) * delta_t + (1/2) * a(i) * delta_t; % Update position
t = t + delta_t; % Update time
end
Now just compare the change in position to the exact solution:
Y(end) - Y(1) is the total change in position
(1/2) * g * t^2 is the exact solution
First, get this working and understand it.
Then you can work on adding in the other stuff. E.g., replace the for loop with a while loop with appropriate test condition(s). And you will be using a different equation for a(i) at each step depending on the current states of the parachute and velocity etc. In other words, you will likely have an "if" check somewhere near the top of the loop to determine how to calculate a(i). So you will need to figure out how to code up that "if" test. And how to account for the terminal velocity stuff. Etc.
  7 Comments
Gerald Melins
Gerald Melins on 30 Mar 2015
I need the time check in the while loop, the parachute deploys after 40 seconds
James Tursa
James Tursa on 31 Mar 2015
The time check for the parachute goes in this line:
if( conditions are met for parachute opening )

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!