Code covered by the BSD License  

Highlights from
Reliable and Roubst Design

image thumbnail
from Reliable and Roubst Design by Stuart Kozola
MATLAB Code used in the Jan 2008 Digest Article

myCostFcn(x,simParms)
function mycost = myCostFcn(x,simParms)

%% Unpack simParms structure for Simulink Use
struct2var(simParms)

%% Extract suspension variables
kf = x(1); cf = x(2);
kr = x(3); cr = x(4);

%% Run Simulink model
% Initial Conditions for Simulink Model
theta0 = 0;                 % initial pitch (rad)
thetadot0 = 0;              % initial pitch rate (rad/s)
Z0 = -0.5*Mb*g/(kf+kr);     % initial equilibrium position, assumes full car (m)
Zdot0 = 0;                  % initial bounce rate (m/s)
simTime = [0 8];
sim('mldemo_suspnfast.mdl',simTime,...
    simset('SrcWorkspace', 'current', 'DstWorkspace', 'current'))

%% Compute cost
totalAccel = (Zdotdot + rf * thetadotdot).^2 + ...
             (Zdotdot - rr * thetadotdot).^2;

%% Return final value
mycost = 0.5*max(totalAccel)/56 + 0.5 * sum(totalAccel)/904;
assignin('base','totAccel',totalAccel);

Contact us at files@mathworks.com