function masslauncher_project_template
% This is the 'driver'  function that MATLAB will execute
%1.	Define values for variables
%2.	Set up the constraints for the optimization for the MATLAB optimizer (see the MATLAB tutorial)
%3.	Call the MATLAB optimizer (which will substitute different values for ‘Design Variables’ into the function below, and find the values that give the lowest value for launchvel).  The output of the optimizer is a vector storing the values of mass and stiffness that minimize the launch velocity
%4.	Post-process results – simulate the behavior of the optimal design, plot graphs, calculate the efficiency, etc

% Before running the optimizer, test your code with
%   Design_Variables = [.... enter values of masses/spring stiffnesses for some sensible design ]
predicted_velocity = findlaunchvel(Design_Variables) % This will calculate the launch velocity for your guess and print it

end
function launchvel = findlaunchvel(Design_Variables)
% Function to calculate the launch velocity, given values
% for the masses and spring stiffnesses in the mass launcher
% Design_Variables is a vector that contains a list of the
% values of masses and stiffnesses, eg [m1,m2,m3...,k1,k2,k3...]
% It is best to work with m in lb and k in lb/in.  NB – lb is not a 
% of mass – you have to convert to slugs or blobs to do the calculation. 
%
% This function must calculate a value for variable launchvel – 
% this is the velocity of the topmost mass at the instant that it leaves the % mass launcher.  You will have to use a trick to make sure the optimizer
% maximizes, rather than minimizes, the launch velocity
%1. Define values for masses and spring stiffnesses, eg m1 = Design_Variables(1), m2 = Design_Variables(2) etc
%2. Do any necessary unit conversions (eg convert mass from lb to slugs or blobs); specify initial conditions; the time interval for the simulation, etc.
%3.  Call ode45 here. Don’t forget to use the ‘options’ variable so matlab can detect the separation of the missile.
%4.  The ODE solver will give you a vector of time values, and a matrix of solution values, as usual.  You will need to determine the launch velocity from the solution (it will be stored somewhere in the solution  matrix).
%5. Before running the optimization, it’s a good idea to test this function by itself with some sensible guess for the design variables.  You can plot the solution and make sure it looks sensible.  If you use computer simulations to help with design, you always need to be very careful – a tiny error in the code can cause big problems! 


end
function dwdt = diffeq(t,w, plus any variables eg m1,m2,m3,k1,k2,k3)
%  Function to calculate the time derivative of the variables
%  describing the position and velocity of the masses.
%Enter code for your equations of motion here
end
function [eventvalue,stopthecalc,eventdirection] = event(t,w)
%  Function to identify the point where the top mass is launched.
%  You will have to use some physics to find a criterion to detect this point

%Enter code to detect the separation here – make ‘eventvalue’ = a formula that goes to zero at separation.
end 
