•

##### Document Actions

The assignment begins with the following steps, which you should carefully work and understand.

1. To run Simulink, first get into Matlab and then from the Matlab command prompt typ simulink .
2. Under the file menu, select New, then Model. A window will appear which will be your drawing window for the block diagram.
3. You will be creating the block diagram shown. This is the Simulink representation of Figure 6.36(b).

Begin by placing the transfer function representing the motor. To do this:

1. In the Simulink menu, double-click on the icon labeled "Continue to open up its selections.
2. From the Continuous menu, drag the icon labeled Transfer Fcn'' to the drawing window.
3. In the drawing window, double-click on the Transfer Fcn Icon. A small window will appear that will allow you to enter the parameters of the transfer function as its numerator polynomial. The transfer function you want (representing the motor) is

The numerator polynomial is [1] . The denominator polynomial is [1 8 0] , representing the polynomial . Enter the parameters appropriately and click on Done when you are finished.
4. Now place the Gain block (which represents the block ). From the Math Operations menu, drag the icon labeled Gain'' to the drawing window and place it appropriately. Adjust the gain of the Gain block by double-clicking on the gain icon and setting the parameter. Set the gain to 80 to begin with.
5. Connect the gain block to the transfer function: Place the cursor on the output arrow of the amplifier and drag until it touches the input of the transfer function block. When you release the mouse button, the blocks will be connected (if you have placed everything correctly) and an arrow will appear indicating that the blocks are connected. (If you make a mistake, you can delete a connection by clicking on it to select, then pressing the Delete key.)
6. Place the summation block on your block diagram.
1. Drag the Sum icon from the Math Operations menu to the appropriate place on the drawing window.
2. Set the signs of the inputs so that the top input is and the bottom input is . This is done by double clicking on the icon and setting the list of input signs as desired.
3. Connect the output of the summation block to the input of the gain block.
4. Connect the output of the transfer function to the input of the summation block. (You can draw each segment of the line separately.)
7. Provide the input to the system by adding a Step Input.
1. In the Simulink menu, double-click on the Sources icon to open up its selections. You will see a variety of interesting sources.
2. From the Sources menu, drag the Step Input icon to an appropriate location in the drawing window.
3. Double-click on the Step Input icon to set its parameters. Set the step time to 0 (so the step occurs right at time ). The initial value and final values are correct by default.
4. Connect the output of the Step Input icon to the input of the Sum icon.
8. The basic block diagram is now complete. However, you must provide some means of looking at what is going on in the simulation. What you will do is tell the system to save its output into a Matlab variable. Then the Matlab plotting facilities can be used to plot the results of the simulation.
1. In the Simulink menu, double-click on the Sinks icon to open up its selections. In data processing terminology, a Source is something that provides data (like a signal generator), and a Sink is something that consumes data (like the drain in a sink).
2. From the Sinks menu, drag the To Workspace icon to an appropriate location in the drawing window.
3. The text shown in the icon yout is the name of the Matlab variable that the data is saved to.
4. Connect the output of the transfer function to the input of the To Workspace icon. Note that an output can be routed to several different places, so this connection is just like all the others, even though the transfer function is already connected to something.
9. For purposes of plotting the results, we also need to know the "time'' in the simulation. What is happening is this: the Simulink program converts the block diagram into a set of differential equations. Then, using numerical techniques to solve the differential equation, it finds the outputs as necessary. As you will recall from last quarter when you did numerical integration of differential equations, there must be some kind of variable representing time. Despite this lengthy explanation, it is quite easy to accomplish.
1. From the Sources menu, drag the Clock icon to the drawing window. The Clock has an output that is simply the time variable in the simulation. There are no parameters associated with this device.
2. From the Sinks menu, drag the To Workspace icon to the drawing window.
3. Double-click on the To Workspace Icon to change the name of the workspace variable. Call the variable t , to represent time.
4. Connect the output of the Clock icon to the input of the To Workspace Icon.
10. You have now completed the drawing of the block diagram. Before doing anything else, you should save the block diagram to a file for future use. This is done using the Save option under the File menu. If you are running in the PC lab, you will want to make sure you save to a diskette.
11. Set the simulation parameters. In the Simulation menu in the drawing window, select the command Parameters. Several options will appear. You do not need to worry about most of them. The one of interest is the Stop Time: Set it to 5.

(The buttons at the top select the particular algorithms used for the numerical solution of the differential equations. If you were to select the Euler button, you would be doing the same kind of solution you did in your programming assignments last quarter. The other options are more sophisticated, and hence more accurate, numerical techniques. You should probably just leave it at the default setting.)

12. You are now ready to simulate. Under the Simulation menu in the drawing window, simply select the command Start. The computer will beep. That is it! Nothing appears on the screen, because the results of the simulation are saved into Matlab variables.
13. To see the results of the simulation, you will need to go back to the Matlab window. From the Matlab window, enter the Matlab command

plot(t,yout)

which plots the variable t versus the variable yout . As you recall, these are the variables that Simulink uses. Compare the results of the plot command with Figure 6.36(c) in the book for . They should be very similar! (If not, make sure that you have the parameters set correctly in the Sum, the Gain, and the Transfer function. Also make sure that the lines are actually connecting as they should be.)

I don't know about you, but I think this is pretty neat! It sure beats solving differential equations by hand.