MATLAB PROBLEM Problem number 1: Butter bot’s sole purpose was once to pass butt
ID: 3873802 • Letter: M
Question
MATLAB PROBLEM
Problem number 1: Butter bot’s sole purpose was once to pass butter across the dining room table. Now we are upgrading it to put the correct amount of butter on a piece of toast. Write a function called howMuchButter for Butter Bot to do this. It should take two inputs: - toastThickness, the thickness of the toast slice in inches - toastArea, the area of the slice of toast in square inches It should return one output, butterAmount. This output should be:
- The string ‘Small amount of butter’ if the toast thickness is less than 0.5 inches AND the toast area is less than 9 square inches squared.
- The string ‘Moderate amount of butter’ if the toast thickness is between 0.5 and 0.75 inches OR the toast area is between 9 and 16 inches squared.
- The string ‘Lots of butter’ if the toast thickness is greater than 0.75 inches AND the toast area is greater than 16 inches squared.
- If the toast thickness and area do not fall into any of these ranges, return the string ‘Find a new piece of toast!’
2. problem number 2: You are an engineer working on a battery powered car. You are trying to come up with a simple model for how far your car can travel on a certain amount of battery charge. However, your data shows that there is not a single equation to describe your car’s behavior. Instead, you know the following: - When your car’s battery has between and including 100% and 81% charge, each percentage point drained takes the car 10km
-Below 81% and going down to 51%, each percentage point drained takes the car 8km.
-Below 51% and going down to 21%, each percentage point drained takes the car 7km.
- Below 21% and going down to 6%, each percentage point drained takes the car 5km.
- At 5% and below, each percentage point drained takes the car 4km.
Write a program to simulate this car. Your program should be in the form of a function. It should take one input, an amount of battery remaining, and return one output, the distance the car can travel. Your input can be any whole percentage between 0 and 100. Your program does not need to work with decimals. You will need to use conditional statements to implement the above information to simulate this car. For example, a car with 34% battery would go: - 7km per percentage for 14 percentage points, for a total of 98km. - 5km per percentage for 15 percentage points, for a total of 75km. - 4km per percentage for 5 percentage points, for a total of 20km. For a grand total of 193km.
Explanation / Answer
PLEASE FOLLOW BELOW INSTRUCTIONS CAREFULLY
1) create file howMuchButter.m and paste below code
function result = howMuchButter(toastThickness,toastArea)
%writing if else statement depending on given conditions
if toastThickness < 0.5 && toastArea < 9
result = 'Small amount of butter';
elseif (toastThickness > 0.5 && toastThickness < 0.75) || (toastArea > 9 && toastArea < 16)
result = 'Moderate amount of butter';
elseif toastThickness > 0.75 && toastArea > 16
result = 'Lots of butter';
else
result = 'Find a new piece of toast!';
end
2) create test.m and paste below code(for your test)
close all
clear all
clc
result = howMuchButter(0.65,16)
IF YOU RUN test.m AND YOU WILL GET BELOW OUTPUT
result =
'Moderate amount of butter'
>>
-------------------------------------------------------------------------------------------------------------------------------------------------
2) please create car_travel.m and paste below code
function result = car_travel(battery_amount)
%adding condition given in problem statement
if battery_amount < 100 && battery_amount >= 81 %100% and 81% charge
result = (battery_amount - 80) * 10 + 20 * 8 + 20 * 7 + 15 * 5 + 5 * 4;
elseif battery_amount < 81 && battery_amount >= 51 % Below 81% and going down to 51%
result = (battery_amount - 50) * 8 + 20 * 7 + 15 * 5 + 5 * 4;
elseif battery_amount < 51 && battery_amount >= 21 % Below 51% and going down to 21%
result = (battery_amount - 20) * 7 + 15 * 5 + 5 * 4;
elseif battery_amount < 21 && battery_amount >= 6 % Below 21% and going down to 6%
result = (battery_amount - 5) * 5 + 5 * 4;
else
result = battery_amount * 4;
end
PLEASE CREATE test.m AND PASTE BELOW CODE.
close all
clear all
clc
result = car_travel(34)
PLEASE RUN test.m and YOU WILL GET BELOW OUTPUT
result =
193
>>
DO LET ME KNOW IN COMMENT SECTION FOR DOUBT YOU HAVE
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.