Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to use if/else to write the Matlab User-defined Statement and here is the

ID: 3632428 • Letter: I

Question

I need to use if/else to write the Matlab User-defined Statement and here is the problem:

A. Does the student own a car? If yes than:
1. What is the cost of driving?
A. If cost of driving is >= 75
1. Then, what is the difference between the time it takes to drive and the time it takes to walk or take the bus?
A. If driving is >= 10 min. faster than alternate method, then DRIVE
B. If cost of driving is <= 50
1. Is driving <= 10 minutes faster than fastest alternate method (walk or bus)?
A. If False, then DRIVE.
B. If True, If no than:
2. Does taking the bus cost money?
A. If No, then how long does it take to walk and how frequent are the buses?
1. If time to walk is <=15 min, then WALK.
3. If time is <20 min to walk and the bus frequency is >15 minutes, then WALK.
2. Otherwise, BUS.
B. If Yes, then is the time to walk >15 min?
1. If yes, then BUS
2. If no, then WALK

Making flowchart may be make easier to write the Matlab statement of this problem...

So, the matlab code should start with the function name and the inputs..
the inputs will be:
student %number of students
car %if it has a ownership ~ 1=true, 2=false
ttimewalk %time to walk
ttimeauto %travel time for driving
costauto % cost of parking
ttimebus % time to take the bus
costbus % cost per one way ticket
freqbus % frequency of the bus, time between buses
busstop % distance from home to the bus stop


I need clear Matlab Statement that will go into the calculation section to get the outputs.

Note: There are three types of mode (car, bus, and walk). There are total 9 inputs to put into the functions.

Explanation / Answer

Note: i followed ur instructions. but there is a flaw. nothing is being output when cost of driving is in between 75 and 50

clear;clc
n=input('Do you own a car? ','s');
if strcmp(n,'yes')
cost = input('Cost of driving: ');
if cost >= 75
diff = input('What is the difference between the time it takes to drive and the time it takes to walk or take the bus?');
if diff >= 10
disp('Drive');
end
elseif cost <= 50
diff=input('Is driving <= 10 minutes faster than fastest alternate method (walk or bus)?','s');
if strcmp(diff,'no')
disp('Drive');
elseif strcmp(diff,'yes')
n = 'no';
end
end
end

if strcmp(n,'no')
bus = input('Does taking the bus cost money?','s');
if strcmp(bus,'no')
walk = input('how long does it take to walk: ');
frq = input('bus frequency: ');
if walk <= 15 | (walk <20 & frq > 15)
disp('walk');
else
disp('Bus');
end
elseif strcmp(bus,'yes')
walk = input('how long does it take to walk: ');
if walk > 15
disp('bus');
else
disp('walk');
end
end
end