Chat with us, powered by LiveChat turn in two m-files, a function and a script | Writedemy

turn in two m-files, a function and a script

turn in two m-files, a function and a script

Homework 5

For your homework, 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 – hw5_yourinitials_func.m

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 1×3 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 1×1 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 – hw5_yourinitials_script.m

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

1. Initialize a 1×7 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 1×30 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”

Bonus

In the function, if there is 1/4 of an item left in stock (i.e. 25 left after starting with 100), that items price

must be doubled. In the script add another 1×7 vector called WeeklyRevsInflated. Follow the same

instructions as step 3 of the script and change the labels and title.

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order