Code covered by the BSD License

# Using Analytical Tools to Gain Insight and Speed-up Num. Analysis in MATLAB & Symbolic Math Toolbox

### Deepak Ramaswamy (view profile)

28 Jan 2013 (Updated )

files from the webinar

constraintFcnNumeric(x)
```%
% Copyright 2012 The MathWorks, Inc.
function [c,ceq] = constraintFcnNumeric(x)

% Input parameters
rocketStartTime = x(1); %#ok<NASGU>
engineOffTime = x(2);
chute1Time = x(3);
chute2Time = x(4);

% simulate a run
[time, vel] = simulateRun(x);

% calcualte relevant distances
oneMile = 1609.344;
idx1 = time < engineOffTime ;

if max(vel) > mph2mps(1000);
t1000_1 = spline(vel(idx1), time(idx1), mph2mps(1000));
t1000_2 = spline(vel(~idx1), time(~idx1), mph2mps(1000));

idx2 = (time>t1000_1) & (time<t1000_2);
time1000 = [t1000_1, time(idx2)', t1000_2];
vel1000 = [mph2mps(1000), vel(idx2)', mph2mps(1000)];

dist1000 = trapz(time1000, vel1000);
else
dist1000 = 0;
t1000_2 = 0;
end

totalD = trapz(time,vel);
timeBackUnder1000 = t1000_2;
chute1OpenVel = spline(time(~idx1), vel(~idx1), chute1Time);
chute2OpenVel = spline(time(~idx1), vel(~idx1), chute2Time);

% set constraints
c = [
oneMile - dist1000
totalD - 10*oneMile
9.5*oneMile - totalD
timeBackUnder1000 - chute1Time
engineOffTime - timeBackUnder1000
chute1OpenVel - mph2mps(600)
chute2OpenVel - mph2mps(350)
];

ceq = [];

end

function y = mph2mps(x)
y = x*1609.344/3600;
end
```