Mathematical Modeling: Conditional Statements Overview
In this information-rich resource, delve into the purpose and description of conditional statements in Maple programming for mathematical modeling. Explore the application of conditional statements in branching code sections based on control expressions. Get a sneak peek into Poisson distribution and how it intertwines with conditional statements for precise modeling. Don't miss the example scenarios and insightful ideas presented here.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
MAT 4830 Mathematical Modeling Section 1.3 Conditional Statements http://myhome.spu.edu/lauw
Questions What is the purpose of a conditional statement?
Questions Describe a conditional statement in Maple.
Starting Next Monday You will be writing codes without an example that you can just modify on. You need to be able to write complete Maple programs on your own. No two should sit next to each other today. Learn to debug your own program is an important learning process.
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
Example 0 On average, random customers per hour come into a local Starbucks during the morning rush hours. customers per hour
Example 0 What is the probability that exactly ? customers come in within a time period of length ? hours? customers in a period of length k T
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 = = ?
Idea: Approximate by a binomial model r.v. ?=no. of customers comes in within a time period of length ? 0 T n k n k = k ( ) (1 ) P X k p p n k n k = k lim n (1 ) p p
Idea: Approximate by a binomial model r.v. ?=no. of customers comes in within a time period of length ? 0 T n k n k = k ( ) (1 ) P X k p p n k n k = = k ( ) lim n (1 ) P X k p p
Theorem 1 n k n k = = k ( ) lim n (1 ) P X k p p ( ) k T k = T e !
Why? Calculus Formula: n x n = + x lim 1 n e ( ) n n T T = + = T lim 1 n lim 1 n e n n ( ) k n k T k n k = k T lim n (1 ) p p e !
Why? n k n k = k (1 ) p p n T n = T lim 1 n e ( ) k n k T k n k = k T lim n (1 ) p p e !
Poisson Distribution P(?,T) ( , ) X P T ( ) k T k = = = = T Prob. Density Fun. ( ) ( ) , 0,1,... f k P X k e k ! = = Mean EX = T Std. D. T Team HW#1
Team Homework #1 Use the definition of expected value and the Taylor expansion k x k = x e ! = 0 k Do not use the moment generating function.
Poisson Distribution Model arrival process Approximate binomial dist. when ? is large ( ) k n k T k n k k T (1 ) Vs p p e !
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
Example 1 Consider the piecewise defined function 2 0 0 x x x x = ( ) f x For each interval, we need a different formula to compute the function values
Example 1 Consider the piecewise defined function 2 0 0 x x x x = ( ) f x For each interval, we need a different formula to compute the function values Q: Input=? , Output=?
2 0 0 x x x x Example 1 Version 1 = ( ) f x >fun:=proc(x) local 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); end: #Program to compute the given #piecewise defined function #Function value #Output function value
2 0 0 x x x x Example 1 Version 1 = ( ) f x >fun:=proc(x) local 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); end: #Program to compute the given #piecewise defined function #Function value #Output function value > fun(-2);fun(2); 4 2
Structure of the if-block if condition then block of statements to be executed fi; Statements executed only if the condition is met. Otherwise, the statements will be skipped:
2 0 0 x x x x Example 1 Version 2 = ( ) f x > fun:=proc(x) local value; #Function value if x<0 then value:=x^2; #Case for x<0 else value:=x; #Otherwise fi; print(value); end: #Program to compute the given # piecewise defined function #Output function value
2 0 0 x x x x Example 1 Version 2 = ( ) f x > fun:=proc(x) local value; #Function value if x<0 then value:=x^2; #Case for x<0 else value:=x; #Otherwise fi; print(value); end: #Program to compute the given # piecewise defined function #Output function value > fun(-2);fun(2); 4 2
Structure of the if-block if condition then Statement block 1 else Statement block 2 fi; There are two cases separated by one condition: the condition is met or else:
Example 2 ( x ) 2 + 1 2 if 0 x x + x = ( ) f x 2 1 if 0 2 ( )2 2 x 5 if 2 e x We need 3 branches
( x ) 2 + 1 2 if 0 x x + x = ( ) f x 2 1 if 0 2 Example 2 ( )2 2 x 5 if 2 e x
( x ) 2 + 1 2 if 0 x x + x = ( ) f x 2 1 if 0 2 Example 2 ( )2 2 x 5 if 2 e x > fun(-3);fun(1);fun(3); -14 3 5e(-1)
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;
Homework Read 1.6 for formatting with printf We will not go into this section during lecture You are expected to know how to use printf See webpage