Starting from:

$30

Homework 1 MATLAB Basics Solution

Function Name: ​lemonade




Inputs:




1. (​double​) Number of quarts




Outputs:

(double​) Number of gallons



(double​) Number of pints



(double​) Number of cups



Background:




You and your friends decide to put together a lemonade stand to make a little money. However, when looking at all the different recipes you can make, you notice they’re all in different units! After worrying about the numerous conversions you have to make, you realize you can just write in function in MATLAB to do it for you!




Function Description:




Write a function that has one input- the amount of liquid in quarts, and outputs three different conversions- the amount of liquid in gallons, pints, and cups.




Conversions







1 gallon = 4 quarts




1 quart = 2 pints




1 pint = 2 cups










Notes:




Round your answer to the second decimal place.
Homework 1 - MATLAB Basics













Function Name: ​cookieCutter




Inputs:




1. (​double​) Interior angle of your cookie cutter




Outputs:




1. (double​) Number of sides your cookie cutter will have




Background:




You decide to take a trip to the Invention Studio. When you arrive, you find that they're doing a fun challenge involving cookie cutters! Since you like cookies, you decide to participate. You are handed a slip of paper containing an angle measurement, and you have to make a cookie cutter shaped like a regular polygon with that particular interior angle. Do it successfully and you can keep your cookie cutter! You decide to use your MATLAB skills to help you figure out how to make your cookie cutter.




Function Description:




A regular polygon is a polygon where all the sides and angles are the same, like a square or an equilateral triangle. You also remember that a formula that relates the number of sides of a regular polygon to its interior angle is

























In this equation, is the interior angle in degrees and is the number of sides. Write a function in MATLAB that calculates the number of sides given the interior angle.




Example:




cookieCutter(90) = 4




Notes:




If you're not convinced, try plugging in or . You should get 60 and 90, which is the angle measurement of an equilateral triangle and a square, respectively.
You are guaranteed to have a positive integer number of sides.
Homework 1 - MATLAB Basics













Function Name:​​pizzaParty




Inputs:

(double)​Number of party attendees



(double)​Number of pizzas ordered



Outputs:

(double)​Slices of pizza per person



(double)​Slices of pizza left over



Function Description:




You decide to host a party and buy some pizzas for you and your friends. But, in order to be fair, every person should get the same number of slices of pizza. Any extra slices will be left over and saved for later.




You could try and calculate the pizza slice distribution yourself, but why bother when you can have MATLAB do all the hard work! Given the number of people at the party and the number of pizzas ordered, write a function that outputs how many slices of pizza each person should should receive, and how many slices of pizza will be left over.




For example, if there are 5 people at the party, and 2 pizzas were ordered, each person would get 3 slices, and 1 slice would be left over, so the first output would be 3 and the second output would be 1.




Example




pizzaParty(5, 2) = 3, 1




Notes:




Assume every pizza is cut into 8 slices.



You cannot have fraction slices.



Hints:




You may find the ​floor()​and/or ​mod()​functions useful.
Homework 1 - MATLAB Basics













Function Name: ​orangePeel




Inputs:




1. (​double​) The volume of a sphere, in cm3​




Outputs:




1. (double​) The surface area the sphere, in cm2​




Background:




While enjoying some fruit, you begin to ponder geometry. As you peel an orange, you start to think about how the volume of a sphere is related to the surface area of that sphere and decide to write a MATLAB function to calculate how much orange peel you will have to peel, given the volume of your orange.




Function Description:




The volume of a sphere is given by the following formula:




= 34 πr3



The surface area of a sphere is given by the following formula:




= 4πr2
Given the volume in cubic centimeters, write a MATLAB function to determine the surface area in square centimeters.




Notes:




Round your answer to 2 decimal places.



Use the built-in ​pi ​variable in MATLAB for π.

More products