Top Banner
MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements http://myhome.spu.edu/lauw
42

MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Dec 29, 2015

Download

Documents

Felicia Ramsey
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

MAT 4830Mathematical Modeling

Section 1.4

Conditional Statements

http://myhome.spu.edu/lauw

Page 2: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 3: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 4: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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?

Page 5: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 0

r.v. =no. of devices fail

devices failk

n devices

FF F

( )P failure p

( ) ?P X k

Page 6: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 0 n devices

( ) ?P X k

k devices

n k devices

F F F

Page 7: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 0 n devices

( ) ?P X k

k devices

n k devices

F F F

kp (1 )n kp

n

k

Page 8: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 0 n devices

( ) (1 )k n knP X k p p

k

k devices

n k devices

F F F

Page 9: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 10: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 11: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 12: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 13: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Team Homework #2

A campaign staff knows from experience that only one in every three volunteers called will actually show up to distribute leaflets.

Page 14: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Team Homework #2

How many phone calls must be made to guarantee at least 20 workers with a confidence of 90%?

Page 15: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 16: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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.

Page 17: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 18: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Zeng Section 1.4

Please listen to the explanations before you type in the program.

It takes one minute to explain.

Page 19: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 1 Print the square of the first 10 positive

integers What is the task being repeated?

Page 20: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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:

Page 21: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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:

Page 22: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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:

Page 23: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Structure of the for loopfor loop_index from start_value to end_value do

block of statements to be repeated

od;

Page 24: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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;

Page 25: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 2 Print the square of the first 10 positive

odd integers

Page 26: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 2

Page 27: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 2

> sq2();19

25

Page 28: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 3 Print the square of the first positive

integers

Page 29: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 3 Print the square of the first positive

integers Introduces array and seq Note that these commands are not

necessary here

Page 30: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 3

Page 31: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 3

[ ]x n

[3]x[2]x[1]x

Page 32: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 3

> sq3(2);1, 4

> sq3(5);1, 4, 9, 16, 25

Page 33: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 34: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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

Page 35: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 4 0 1 1 20, 1, k k kF F F F F

Why there is no print statement?

Page 36: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 4 0 1 1 20, 1, k k kF F F F F

Page 37: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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.

Page 38: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

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”.

Page 39: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 5

2 1

0

( 1)sin

(2 1)!

knk

k

x xk

Page 40: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 5

2 1

0

( 1)sin

(2 1)!

knk

k

x xk

Page 41: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Example 5

2 1

0

( 1)sin

(2 1)!

knk

k

x xk

Page 42: MAT 4830 Mathematical Modeling Section 1.4 Conditional Statements .

Homework

See course webpage Read

• 1.3 All HW due next Monday Attempt your HW ASAP Individual HW**