Microsoft Word CS 137 x 0%60/AppDataLocal/Temp/Templ-Hwo1%20(1).zip/HW01-Drillpr
ID: 3874992 • Letter: M
Question
Microsoft Word CS 137 x 0%60/AppDataLocal/Temp/Templ-Hwo1%20(1).zip/HW01-Drillproblems.pdf Function Name: lemonade Inputs: 1. (double) Number of quarts Outputs: 1. (doubie) Number of gallons 2. (double) Number of pints 3. (double) Number of cups Background However, when looking at all the different recipes you can make, y You and your friends decide to put together a lemonade stand to make a little money ou notice they're all in nt units! After worrying about the numerous conversions you have to make, you realize differe you can just write in function in MATLAB to do it for you! Function Description different conversions- the amount of liquid in gallons, pints, and cups Write a function that has one input- the amount of liquid in quarts, and outputs three 1 gallon 4 quarts 1 quart 2 pints 1 pint 2 cups Notes Round your answer to the second decimal place . 5 6Explanation / Answer
round(value,decimalPlace) used for rounding up value. And double() is used for converting value to double, as input s in double, therefore output should be in double and no need of it.
Function in matlab is return as:
function [ouput1, output2,.......,outputn] = functionName(input1,input2......,inputn)
......
......
end
Here is the function for above problem
function [gallons,pints,cups] = convertFromQuarts(quarts)
tempGallons = quarts / 4; %converting quarts to gallon
tempPints = quarts *2; %converting quarts to pints
tempCups = tempPints * 2; %converting pints to cups as cup = 2* pint
%now using round(value,decimalPoint) for rounding up to 2 decimal place
%double is used for convert output to double. (Output is already in double. you can remove it).
gallons = double(round(tempGallons,2));
pints = double(round(tempPints,2));
cups = double(round(tempCups,2));
end
Output
>>[gallon,pints,cups] = convertFromQuarts(256.65)
a =
64.1600
b =
513.3000
c =
1026.6000