# Step 11. Modeling the Demand Cycle

The adoption fraction in our model is constant each period. Actually it changes in a complex way since the demand on our product follows the cycle of the seasons. The peak of the demand is in summer while in winter the product is in little demand. There is also a little peak in adopter activity before the New Year holiday. We want to model the demand cycle and its affect on the adoption fraction in our model.

### Adding experimental data to the model

Assume that we have experimental data how the average demand on the product changes during the year. We will use a table function to add this data to our model. Table function is a function defined in the table form. It returns tabulated values for defined argument values. If the function argument does not correspond to any of the tabulated values, table function computes a value based on the chosen interpolation. Define the demand curve with a table function
1. Drag the Table Function element from the System Dynamics palette onto the Main diagram.
2. Go to the table function's Properties and set up the function properties.
3. Name the function demand.
4. Define data for a table function in the Table Data table. Each "argument-value" pair is specified in an individual row of the table. To define pair of values, click the empty Argument cell and enter a new argument of the function. Then click the adjacent Value cell to the right and enter the function value for this argument. Define the function values as in the following figure: 1. Define how the table function is interpolated. From the Interpolation drop-down list, choose Linear. The function will take a straight line between data points.
2. Define how the function behaves when the provided arguments are out-of-range. From the Out Of Range drop-down list, choose Nearest option. In the case of out-of-range arguments the function will raise an error. The function will use the nearest valid argument for out-of-range arguments.

Finally you will see how the demand curve looks in the function's preview chart on the function's properties page: Now we want to model how the adoption fraction depends on the current demand on the product. Therefore we will define a custom function and replace the AdoptionFraction parameter with the dynamic variable, which value is calculated according to this function. Define a function evaluating the adoption fraction

1. Drag the Function element from the Agent palette onto the Main diagram.
2. Go to the function's Properties and name the function adoptFraction.
3. Specify that the function returns the double value. Choose the Returns value option and leave double as the Return Type.
4. Our function should have one argument to pass the current time value to the function. In the Arguments section of the properties, add argument with Name: time and Type: double.
5. Open the Function body section of the Properties and enter the function expression. Type here the following string instead of existing one:
return demand( getMonth() 1 )/200.0;

This expression calculates the demand for the current month. Finally, to obtain the adoption fraction value, the demand value is divided on the conversion factor.

getMonth() is AnyLogic predefined function. You can use frequently used functions (sin, time, getDay(), etc.) in your expressions. Entering expressions, you can use code completion, where predefined functions are listed as well as variables.

Finally, we will replace the adoption fraction constant with the dynamic variable evaluating its value with the created function. Replace AdoptionFraction parameter with a dynamic variable

2. Create the AdoptionFraction dynamic variable. Set the variable's formula to adoptFraction(time()). Thus, the dynamic variable's value will be computed by our function. The function takes one argument, time().
time
() function returns the current model time. Set DiscardRate to be displayed by the lower time plot

1. Just add DiscardRate as one more data item to be displayed by this plot.
2. Specify Discard rate as the title of this data item.

Set model to stop at time 20 and run the model. You can see that now the behavior of a model deviates above and below an equilibrium point since the adoption rate and the discard rate oscillate. Reference model: Bass Diffusion - Phase 4 Step 10. Modeling replacement purchases Step 12. Modeling a promotion strategy