Need help making a MATLAB program for problem 2 please. Thanks! t have elapsed.
ID: 3827024 • Letter: N
Question
Need help making a MATLAB program for problem 2 please. Thanks!
t have elapsed. Prompt the user to enter an array of amounts carbon 14 present using the input function. Then prompt the user to enter an array of current amounts of carbon 14 present using another input function. Given the decay constant for carbon 14 0.00012097 per year, determine the amount of time that has elapsed for each pair of inputs. Assume both arrays are the same size and that the users enters larger values for the original amounts than for the current amounts and Problem 2: Someone has created the following code to display the frequency of subway trains in a terminal and the names of the train lines are A, B, C, Dand E. Rewrite the code using a switch structure (rather than the nested if), but do not change the prompt. You may assume the user enters an upper case letter at the prompt. (No if, iflelse, or iflelseif structures should be used) Line input ('Enter the line s') if Line 'A' & Line 'E' if Line disp ('This train arrives every 12 minutes. else disp ('This train arrives every 18 minutes. end else if Line 'A' disp ('This train arrives every 24 minutes. else if Line E disp 'This train is not in service. elseExplanation / Answer
The if else in the code can be done in switch case using 5cases.
Case A,{B,D},C,E and other than these.
For multiple switch condition we use {} to embed .
Matlab code below:
Line=input('Enter the line.','s')
switch Line
case 'A'
disp('This train arrives every 24 minutes.')
case {'B','D'}
disp('This train arrives every 18 minutes.')
case 'C'
disp('This train arrives every 12 minutes.')
case 'E'
disp('This train arrives every 30 minutes.')
otherwise
disp('This train is not in service.')
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.