Chapter Contents Previous Next
 The MODEL Procedure

## Example 14.7: Spring and Damper Continuous System

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

[(disp - LAG(disp))/dt] = velocity

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 step-size and error-monitoring 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 Spring-Mass-Damper 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

 Simulation of Spring-Mass-Damper System

 The MODEL Procedure

 Model Summary Model Variables 5 Control Variables 5 Equations 5 Number of Statements 5 Program Lag Length 1

 Model Variables force(-200) disp(10) vel(0) accel(-20) time(0) Control Variables mass(9.2) c(1.5) dt(0.1) k(20) run(1) Equations force disp vel accel time

 Simulation of Spring-Mass-Damper System

 The MODEL Procedure Dynamic Simultaneous Simulation

 Data Set Options DATA= ONE OUT= A

 Solution Summary Variables Solved 5 Simulation Lag Length 1 Solution Method NEWTON CONVERGE= 1E-8 Maximum CC 8.68E-15 Maximum Iterations 1 Total Iterations 99 Average Iterations 1

 Observations Processed Read 100 Lagged 1 Solved 99 First 2 Last 100

 Variables Solved For force disp vel accel time

 Simulation of Spring-Mass-Damper System

 The MODEL Procedure Dynamic Simultaneous Simulation

 Data Set Options DATA= ONE OUT= B

 Solution Summary Variables Solved 5 Simulation Lag Length 1 Solution Method NEWTON CONVERGE= 1E-8 Maximum CC 1.32E-15 Maximum Iterations 1 Total Iterations 99 Average Iterations 1

 Observations Processed Read 100 Lagged 1 Solved 99 First 2 Last 100

 Variables Solved For force disp vel accel time

 Simulation of Spring-Mass-Damper System

 The MODEL Procedure Dynamic Simultaneous Simulation

 Data Set Options DATA= ONE OUT= C

 Solution Summary Variables Solved 5 Simulation Lag Length 1 Solution Method NEWTON CONVERGE= 1E-8 Maximum CC 3.93E-15 Maximum Iterations 1 Total Iterations 99 Average Iterations 1

 Observations Processed Read 100 Lagged 1 Solved 99 First 2 Last 100

 Variables Solved For force disp vel accel time

Output 14.7.2: Overlay Plot of all Three Simulations

 Chapter Contents Previous Next Top