Program Development and Grant Writing for Social Workers
SOWK 665

Spring 2015
316
9. Simulations and Random Numbers
0.6
0.55
0.5
0.45
0.4
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
9.4.3 Random Motion
Let us now consider a particle in a box and ask the question of how likely it is
to hit the east wall. We assume that the western wall repels t
Program Development and Grant Writing for Social Workers
SOWK 665

Spring 2015
320
9. Simulations and Random Numbers
1
(
global mu
mu = 0.4;
xold = 0.25;
xnew = map(xold);
0
)
This example has been given for the map xn+1 = f (xn , ) = xn (1 xn ). The
command global allows the program to know the value of variables globally.
Any rout
Program Development and Grant Writing for Social Workers
SOWK 665

Spring 2015
3.4 Conditional Statements
87
MATLAB complains about precedence and invites the user to nd out more
by using help precedence.
It is convenient at this stage to introduce some of the other commands
which are available to us when constructing conditional st
Program Development and Grant Writing for Social Workers
SOWK 665

Spring 2015
6.1 Introduction
183
should be noted that the nth diagonal is shorter by n than the leading diagonal, for instance if x = ones(3,1) then diag(x) produces a threebythree
matrix whereas diag(x,1) produces a fourbyfour matrix as does diag(x,1).
Consid
Program Development and Grant Writing for Social Workers
SOWK 665

Spring 2015
90
3. Loops and Conditional Statements
9
6
msg = Enter first three letters of the month: ;
month = input(msg,s);
month = month(1:3); % Just use the first three letters
if lower(month)=feb
leap = input(Is it a leap year (y/n): ,s);
end
switch lower(month)
Program Development and Grant Writing for Social Workers
SOWK 665

Spring 2015
10
1. Simple Calculations with MATLAB
ans =
4
> z = 45/180*pi; cos(z)sin(z)
ans =
1.1102e16
> log(exp(2+cos(pi)
ans =
1
> tan(30/180*pi)/(tan(pi/4)+tan(pi/3)
ans =
0.2113
The values of these expressions should be 3/2, 3/4, 4, 0, 1 and 1/(3 + 3).
Notice