Sie sind auf Seite 1von 4

System Modeling and Simulation (IV1200) Homework 1

Solve the following problems using a spreadsheet program such as Excel, MATLAB, and
Simulink. In order to get one bonus point you should send your complete and correct answer
including your program files by email not later than Monday, September 7th. The homeworks
are individual assignments and copying from others homeworks are strictly prohibited.
1. Use a spreadsheet program (Excel) to devise a Monte Carlo experiment to estimate
the value of , as in the equation for the area of a circle.
A = r2
Hint: Consider a quarter circle with unit radius inside a unit square. Throw a random
dart onto the unit square.
2. Enter these commands in MATLAB:
>> X = rand(12, 100000);
>> S = sum(X);
>> hist(S, 25)
Considering the histogram plotted by MATLAB, what can you say about the distribution of the variable S? Motivate your answer.
3. Use Simulink and MATLAB to simulate the predator-prey model discussed in the
first lecture, i.e. the following differential equation:
(
d
dt x(t) = rx(t) ax(t)y(t)
d
dt y(t) = sy(t) + bx(t)y(t)
Assume these values for constants r = 0.001, a = 2 106 , s = 0.01, b = a/2, and the
initial conditions x(0) = 12000 and y(0) = 600. Set the stop time of the simulation to
4000 and the Fixed-step size to 1 (see below) and simulate the system.
Change the initial condition x(0) = 50000 leaving other values unchanged and run
the simulation. How does this affect the result of the simulation? Are the predators
exterminated?

Getting Started With Simulink


Simulink is a software package that is included in MATLAB and is used to numerically solve
Ordinary Differential Equations (ODE). An ODE is a relation that contains functions of only
one independent variable (usually time), and one or more of its derivatives with respect to
that variable.
Simulation of a simple model
As an example we simulate a simple mathematical model of a single mass on a spring, which
is connected to a wall, i.e. the ordinary differential equation:
F = kx = m

d2 x
d2 x
k

= x,
2
2
dt
dt
m
1

where m is the mass, k is the spring constant and x is the distance from the equilibrium
position. Of course this equation can be solved analytically, but there are many ODE that
have no analytical solution, especially those that are nonlinear.
Start Simulink and open the Simulink Library Browser:
1. Start MATLAB.
2. Enter simulink in the MATLAB Command Window.
The Simulink Library Browser opens. The Library Browser displays the Simulink block

Figure 1: Simulink Library Browser


libraries installed on your system. You build models by copying blocks from a library into a
model window.
The block library Commonly Used Blocks contains a group of the most commonly used blocks,
such as the Constant, Scope, and Sum blocks. Each of the blocks in this library are also
included in other libraries, but for solving the spring system and the homework you need only
Commonly Used Blocks. To create a new model, select:
File > New > Model
in the Simulink Library Browser. The software opens an empty model window.
A model is composed by dragging blocks into the model window and connecting them like
the figure below. Build the model of the spring system as the figure below:
We have used two Integrator blocks, one Gain block and one Scope block. Integrator blocks
are used to integrate the signal twice, the Gain block increases the signal input by multiplying
it by a factor and the Scope block is used to show the value of x(t) graphically.
Before you run the model you should specify some initial conditions and values. Double click
on integrator1 and set the initial condition to 2, this will be the value of x(0). You can leave
the initial condition of integrator 2 unchanged, i.e. x0 (0) = 0. Set the Gain to 4 for example.
2

Figure 2: Simulink Model Window

Figure 3: Model of a Spring System


Open the Configuration Parameters windows from the menu Simulation.
Set the Stop time of the simulation to 10. You should define the Fixed-step size, otherwise it
will be defaulted to 0.2 and you get a warning when you run the simulation. Set it to 0.01,
by changing this value you control the size of the numerical error and the run-time of the
program. Another parameter that influences these values is the Solver you choose. All the
ODE solvers are suitable for our purpose and you can leave this field unchanged. ODE with
higher numbers have a smaller error.
Finally, double click on the Scope block to open the scope window and view the result after you
start the simulation by either pushing the start button or choosing Start from the Simulation
menu.

Figure 4: Simulink Configuration Window

Figure 5: Simulink Scope Window

Das könnte Ihnen auch gefallen