Chapter Contents 
Previous 
Next 
The MODEL Procedure 
This model simulates the mechanical behavior of a spring and damper system shown in Figure 14.80.
Figure 14.80: Spring and Damper System Model
A mass is hung from a spring with spring constant K. The motion is slowed by a damper with damper constant C. The damping force is proportional to the velocity, while the spring force is proportional to the displacement.
This is actually a continuous system; however, the behavior can be approximated by a discrete time model. We approximate the differential equation
with the difference equation
This is rewritten
where dt is the time step used. In PROC MODEL, this is expressed with the program statement
disp = lag(disp) + vel * dt;
This statement is simply a computing formula for Euler's approximation for the integral
If the time step is small enough with respect to the changes in the system, the approximation is good. Although PROC MODEL does not have the variable stepsize and errormonitoring features of simulators designed for continuous systems, the procedure is a good tool to use for less challenging continuous models.
This model is unusual because there are no exogenous variables, and endogenous data are not needed. Although you still need a SAS data set to count the simulation periods, no actual data are brought in.
Since the variables DISP and VEL are lagged, initial values specified in the VAR statement determine the starting state of the system. The mass, time step, spring constant, and damper constant are declared and initialized by a CONTROL statement.
title1 'Simulation of SpringMassDamper System'; /* Generate some obs. to drive the simulation time periods */ data one; do n=1 to 100; output; end; run; proc model data=one; var force 200 disp 10 vel 0 accel 20 time 0; control mass 9.2 c 1.5 dt .1 k 20; force = k * disp c * vel; disp = lag(disp) + vel * dt; vel = lag(vel) + accel * dt; accel = force / mass; time = lag(time) + dt;
The displacement scale is zeroed at the point where the force of gravity is offset, so the acceleration of the gravity constant is omitted from the force equation. The control variable C and K represent the damper and the spring constants respectively.
The model is simulated three times, and the simulation results are written to output data sets. The first run uses the original initial conditions specified in the VAR statement. In the second run, the time step is reduced by half. Notice that the path of the displacement is close to the old path, indicating that the original time step is short enough to yield an accurate solution. In the third run, the initial displacement is doubled; the results show that the period of the motion is unaffected by the amplitude. These simulations are performed by the following statements:
/* Simulate the model for the base case */ control run '1'; solve / out=a; run; /* Simulate the model with half the time step */ control run '2' dt .05; solve / out=b; run; /* Simulate the model with twice the initial displacement */ control run '3'; var disp 20; solve / out=c; run;
The output SAS data sets containing the solution results are merged and the displacement time paths for the three simulations are plotted. The three runs are identified on the plot as 1, 2, and 3. The following code produces Output 14.7.1 through Output 14.7.2.
/* Plot the results */ data p; set a b c; run; title2 'Overlay Plot of All Three Simulations'; proc gplot data=p; plot disp*time=run; run;Output 14.7.1: Printed Output Produced by PROC MODEL SOLVE Statements



Output 14.7.2: Overlay Plot of all Three Simulations
Chapter Contents 
Previous 
Next 
Top 
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.