Create a function with three scalar inputs number of krabby


For your assignment, turn in two m-files, a function and a script.

The Krusty Krab is open daily and features 3 items on the menu: Krabby Patties, Kelp Rings, and Coral Bits. They each cost $1.25, $1.50, and $1.00 respectively.

In this simulation we will assume there are an unlimited number of potential customers who want to order. The Krusty Krab can only close after all items have been sold.

Every customer has a 1 in 3 chance of ordering each item from the menu while all 3 items are in stock. This means that a customer could order 0 items, 1 item, 2 items, or all 3 items (The probability of ordering all three is (1/3)*(1/3)*(1/3) = 1/27).

If an item runs out of stock then the probability of the other 2 items gets raised to a 1 in 2 chance of ordering each item. If there is only 1 item left, then the probability of that item gets raised to a 3 in 4 chance of ordering it.

YOUR FUNCTION -

Create a function with three scalar inputs: number of Krabby Patties (P), number of Kelp Rings(R), and number of Coral Bits(B), and two outputs: total revenue "Rev" a scalar, and inventory "Inv" a matrix.

1. Initialize a 1x3 vector of zeros called Orders. Each row represents a customer. The first column represents Krabby Patties, second is Kelp Rings, third is Coral Bits. The columns should be filled with 0s and 1s. 1s represent if the item was bought and 0s represent if the item was not bought.

2. Initialize a 1x1 vector called CustRev and store the revenue generated from each customer in it.

3. Initialize your Inv vector using the three inputs, P, R, and B. Inv represents the amount of inventory of each of the three items, when a customer is done ordering.

4. Create a while loop to keep the simulation running until all items have been sold. I'd recommend creating a scalar that represents the total number of items remaining, and updating it each iteration.

a. Decide if the customer bought each item with the probabilities listed above and mark the column in Orders with a 0 or 1. Use an "if" statement to adjust the probabilities for each item in an order depending on how many items are left in stock.

b. Update Orders and Inv depending on what items the customer may have bought.

c. In the CustRev vector, calculate the cost of the order and add in tip. 7% tip if they bought 1 item, 10% if they bought 2 items, and 15% if they bought all 3 items.

d. At the end of each iteration in the loop, if the total is still greater than 0, add another row of zeros to Orders, a zero to the end of the CustRev vector, and a new row to the end of Inv that is the current inventory. Basically, these variables grow each iteration.

5. Calculate the total revenue generated from the day and store the value as the output (Rev).

YOUR SCRIPT

Create a script that will compare the total revenues from multiple days of service.

1. Initialize a 1x7 vector of zeros called RevWeek.

2. Use a for loop to call the function 7 separate times, with P=300, R=300, and B=300 as the initial values (inputs) each time. Store the revenue outputs in the RevWeek vector.

3. Each time through the loop, plot each column of the Inventory output on one plot with three separate subplots, using subplot(3,1,...). So on one subplot, you'll have 7 lines representing the value of P throughout the day, and then 7 separate lines for R, and then for B.

4. After the loop is done, plot RevWeek using appropriate titles and axes labels.

5. Create a 1x30 vector of zeros called "RevMonth".

6. Use a for loop to call the function 30 separate times with variables, P=300, R=150, B=150. Store the results in the RevMonth vector.

7. For each iteration, keep track of the number of customers it takes to sell out and store this in a vector too, called "Customers"

8. Create identical plots as you did for the weekly revenue, i.e. Inv and RevMonth. Use a comment in your code to discuss the results in a few sentences.

9. Plot the RevMonth and Customers results on two separate histograms using "hist"

Request for Solution File

Ask an Expert for Answer!!
Other Engineering: Create a function with three scalar inputs number of krabby
Reference No:- TGS02674952

Expected delivery within 24 Hours