MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements http://myhome.spu.edu/lauw
Dec 29, 2015
MAT 4830Mathematical Modeling
Section 1.4
Conditional Statements
http://myhome.spu.edu/lauw
Preview
Review Binomial Distribution Introduce the first type of repetition
statements – the for loop Allow a specific section of code to be
executed a number of times Introduces simple arrays
Example 0
Suppose that there are devices, each with a probability of failure during a given time period. What is the probability that exactly fail during this time period?
n devices
( )P failure p
F
Example 0
devices failk
n devices
FF F
( )P failure p
Suppose that there are devices, each with a probability of failure during a given time period. What is the probability that exactly fail during this time period?
Example 0
r.v. =no. of devices fail
devices failk
n devices
FF F
( )P failure p
( ) ?P X k
Example 0 n devices
( ) ?P X k
k devices
n k devices
F F F
Example 0 n devices
( ) ?P X k
k devices
n k devices
F F F
kp (1 )n kp
n
k
Example 0 n devices
( ) (1 )k n knP X k p p
k
k devices
n k devices
F F F
Binomial Distribution B(n,p)
( , )
Prob. Mass Fun. ( ) ( ) (1 ) , 0,1,...,
Alternatively, ( ) ( ) (1 ) , 0,1,...,
Mean
Std. D. (1 )
k n k
x n x
X B n p
nf k P X k p p k n
k
nf x P X x p p x n
x
EX np
np p
Binomial Distribution B(n,p)
( , )
Prob. Mass Fun. ( ) ( ) (1 ) , 0,1,...,
Alternatively, ( ) ( ) (1 ) , 0,1,...,
Mean
Std. D. (1 )
k n k
x n x
X B n p
nf k P X k p p k n
k
nf x P X x p p x n
x
EX np
np p
Binomial Distribution B(n,p)
( , )
Prob. Mass Fun. ( ) ( ) (1 ) , 0,1,...,
Alternatively, ( ) ( ) (1 ) , 0,1,...,
Mean
Std. D. (1 )
k n k
x n x
X B n p
nf k P X k p p k n
k
nf x P X x p p x n
x
EX np
np p
Team HW #1
Team Homework #1
Use the definition of expected value and the binomial theorem
Do not use the moment generating function. You may need to recall how to shift indices in
a summation (see the hidden slides below for review).
0
( )n
n k n k
k
na b a b
k
Team Homework #2
A campaign staff knows from experience that only one in every three volunteers called will actually show up to distribute leaflets.
Team Homework #2
How many phone calls must be made to guarantee at least 20 workers with a confidence of 90%?
Team Homework #2
How many phone calls must be made to guarantee at least 20 workers with a confidence of 90%?
(at least 20 workers) 0.9P
Minimum
Team Homework #2
Use a binomial model to solve the problem. You need to write a Maple program to help
you solve the problem.You need to explain your methodologies,
arguments, and conclusions carefully.Extra works are welcome – In the past,
students had done more than they were asked to get bonus points.
Zeng Section 1.4
Introduce the first type of repetition statements – the for loop
Allow a specific section of code to be executed/repeated a number of times
Introduces simple arrays
Zeng Section 1.4
Please listen to the explanations before you type in the program.
It takes one minute to explain.
Example 1 Print the square of the first 10 positive
integers What is the task being repeated?
Example 1
>sq:=proc() #program to print the square #of the 1st 10 positive #integers local i; #index for i from 1 to 10 do #A loop to print the integers print(i^2); #output i^2 od; end:
Example 1
i
1 2 101 4 100
i2i
>sq:=proc() #program to print the square #of the 1st 10 positive #integers local i; #index for i from 1 to 10 do #A loop to print the integers print(i^2); #output i^2 od; end:
Example 1
> sq();149
>sq:=proc() #program to print the square #of the 1st 10 positive #integers local i; #index for i from 1 to 10 do #A loop to print the integers print(i^2); #output i^2 od; end:
Structure of the for loopfor loop_index from start_value to end_value do
block of statements to be repeated
od;
Structure of the for loop
The loop_index increase by the default step size 1 everytime the execution of block of statements to be repeated is finished. Different step size can be used by adding “by stepsize” feature.
for loop_index from start_value to end_value do
block of statements to be repeated
od;
Example 2 Print the square of the first 10 positive
odd integers
Example 2
Example 2
> sq2();19
25
Example 3 Print the square of the first positive
integers
Example 3 Print the square of the first positive
integers Introduces array and seq Note that these commands are not
necessary here
Example 3
Example 3
[ ]x n
[3]x[2]x[1]x
Example 3
> sq3(2);1, 4
> sq3(5);1, 4, 9, 16, 25
Example 4
Fibonacci sequence is defined by
0 1 1 20, 1, for 2,3,
{0, 1, 1, 2, 3, 5, }
k k kF F F F F k
Example 4 Write a program that generate the first
terms of the Fibonacci sequence
0 1 1 20, 1, k k kF F F F F
Example 4 0 1 1 20, 1, k k kF F F F F
Why there is no print statement?
Example 4 0 1 1 20, 1, k k kF F F F F
Example 5
2 1 2 1
0 0
( 1) ( 1)sin
(2 1)! (2 1)!
k knk k
k k
x x xk k
Write a program, for the input of and , to approximate the value of by the first sum of the first terms in the Taylor series.
Example 5
2 1 2 1
0 0
( 1) ( 1)sin
(2 1)! (2 1)!
k knk k
k k
x x xk k
This is to demonstrate the basic form of “accumulation”.
Example 5
2 1
0
( 1)sin
(2 1)!
knk
k
x xk
Example 5
2 1
0
( 1)sin
(2 1)!
knk
k
x xk
Example 5
2 1
0
( 1)sin
(2 1)!
knk
k
x xk
Homework
See course webpage Read
• 1.3 All HW due next Monday Attempt your HW ASAP Individual HW**