I need to use if/else to write the Matlab Statement and here is the problem: A.
ID: 3632307 • Letter: I
Question
I need to use if/else to write the Matlab 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...
I need clear Matlab Statement that will go into the calculation section to get right outputs.
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