+ All Categories
Home > Documents > MAT 4830 Mathematical Modeling Section 1.3 Conditional Statements .

MAT 4830 Mathematical Modeling Section 1.3 Conditional Statements .

Date post: 27-Dec-2015
Category:
Upload: christopher-dale-hopkins
View: 215 times
Download: 1 times
Share this document with a friend
Popular Tags:
30
MAT 4830 Mathematical Modeling Section 1.3 Conditional Statements http://myhome.spu.edu/lauw
Transcript
Page 1: MAT 4830 Mathematical Modeling Section 1.3 Conditional Statements .

MAT 4830Mathematical Modeling

Section 1.3

Conditional Statements

http://myhome.spu.edu/lauw

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

Questions

What is the purpose of a conditional statement?

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

Questions

Describe a conditional statement in Maple.

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

Preview

Review Poisson Distribution Introduces the conditional statements Allow the flow of control to branch into

two or more sections of codes based on the truth values of a control expressions

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

Example 0

On average, random customers per hour come into a local Starbucks during the morning rush hours.

customers per hour

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

Example 0

What is the probability that exactly customers come in within a time period of length ?

customers in a period of length k T

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

Idea: Approximate the scenario by a binomial model

Divide into subintervals with equal length. Each interval is small enough such that only at most one customer comes in within the subinterval.

0 T

Consider this as a binomial model.

(a customer walks in within a subinterval) ?p P

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

Idea: Approximate by a binomial model

r.v. X=no. of customers comes in within a

time period of length

0 T

( ) (1 )

lim (1 )

k n k

k n k

n

nP X k p p

k

np p

k

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

Idea: Approximate by a binomial model

r.v. X=no. of customers comes in within a

time period of length

0 T

( ) (1 )

( ) lim (1 )

k n k

k n k

n

nP X k p p

k

nP X k p p

k

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

Theorem 1

( ) lim (1 )

!

k n k

n

k

T

nP X k p p

k

Te

k

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

Why?

Calculus Formula:

lim 1

lim 1 lim 1

nx

n

n nT

n n

xe

n

T

ne

T

n

lim (1 )

!

k

Tk n k

n

n Tp p

k ke

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

Why?

(1 )k n knp p

k

lim 1n

T

n

Te

n

lim (1 )

!

k

Tk n k

n

n Tp p

k ke

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

Poisson Distribution P(,T)

( , )

Prob. Density Fun. ( ) ( ) , 0,1,...!

Mean

Std. D.

k

T

X P T

Tf k P X k e k

kEX T

T

Team HW#1

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

Team Homework #1

Use the definition of expected value and the Taylor expansion

Do not use the moment generating function.

0 !

kx

k

xe

k

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

Poisson Distribution

Model arrival process Approximate binomial dist. when is large

(1 ) Vs

!

k

k n k Tn Tp p e

k k

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

Team Homework #2

A newsboy sells newspapers outside Grand Central Station. He has on average 100 customers per day. He buys papers for 50 cents each, sells them for 75 cents each, but cannot return unsold papers for a refund. How many papers should he buy?

To maximize the expected profit

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

Zeng Section 1.3

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

Example 1 Consider the piecewise defined function

2 0( )

0

x xf x

x x

For each interval, we need a different formula to compute the function values

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

Example 1 Consider the piecewise defined function

2 0( )

0

x xf x

x x

For each interval, we need a different formula to compute the function values

Q: Input=? , Output=?

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

Example 1 Version 12 0

( )0

x xf x

x x

>fun:=proc(x) #Program to compute the given # piecewise defined function local value; #Function value if x<0 then value:=x^2 fi; #Case for x<0 if x>=0 then value:=x fi; #Case for x>=0 print(value); #Output function value end:

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

Example 1 Version 12 0

( )0

x xf x

x x

>fun:=proc(x) #Program to compute the given # piecewise defined function local value; #Function value if x<0 then value:=x^2 fi; #Case for x<0 if x>=0 then value:=x fi; #Case for x>=0 print(value); #Output function value end:

> fun(-2);fun(2);42

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

Structure of the if-blockif condition then

block of statements to be executed

fi;

Statements executed only if the condition is met. Otherwise, the statements will be skipped:

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

Example 1 Version 22 0

( )0

x xf x

x x

> fun:=proc(x) #Program to compute the given # piecewise defined function local value; #Function value if x<0 then value:=x^2; #Case for x<0 else value:=x; #Otherwise fi; print(value); #Output function value end:

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

Example 1 Version 22 0

( )0

x xf x

x x

> fun(-2);fun(2);42

> fun:=proc(x) #Program to compute the given # piecewise defined function local value; #Function value if x<0 then value:=x^2; #Case for x<0 else value:=x; #Otherwise fi; print(value); #Output function value end:

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

Structure of the if-blockif condition then

Statement block 1

else Statement block 2

fi;

There are two cases separated by one condition: the condition is met or else:

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

Example 2

We need 3 branches

2

2

2

1 2 if 0

( ) 2 1 if 0 2

5 if 2x

x x

f x x x

e x

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

Example 2

2

2

2

1 2 if 0

( ) 2 1 if 0 2

5 if 2x

x x

f x x x

e x

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

Example 2

> fun(-3);fun(1);fun(3);-143

5e(-1)

2

2

2

1 2 if 0

( ) 2 1 if 0 2

5 if 2x

x x

f x x x

e x

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

Structure of the if-block

if condition 1 then Statement block 1

elif condition 2 then Statement block 2

... ... elif condition n then

Statement block n else

Final statement block fi;

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

Homework

Read 1.6 for formatting with printf See webpage


Recommended