In: Computer Science
Reuse the code to prompt the user for a specific day, test
whether it is
within range, and then output the estimated concrete strength from
the fitted
curve using polyval. Run your function from the command window for
2
different days to test the functioning of your code. The program
should
preferably loop until the user asks to exit.
where
x = days
y = rain (mm)
x = [0 1 2 3 7 14 28];
y = [0 4 9.5 14 17.5 19.5 25.5];
%use polyfit to second order polynomial
a = polyfit(x,y,2);
xx = linspace(1,28);
yy = polyval(a,xx);
% Matlab script that prompts the user for a specific day, test
whether it is
% within range, and then output the estimated concrete strength
from the fitted
% curve using polyval.
x = [0 1 2 3 7 14 28]; % days
y = [0 4 9.5 14 17.5 19.5 25.5]; % rain (mm)
%use polyfit to second order polynomial
a = polyfit(x,y,2);
%xx = linspace(1,28);
%yy = polyval(a,xx);
done = false;
% loop that continues until the user exits
while ~done
% input the day
day = input('Enter a day(1-28): ');
% validate day to be between [1,28], re-prompt until valid
while day < 1 || day > 28
day = input('Day must be between [1,28]. Enter a day(1-28):
');
end
% calculate the concrete strength from the fitted curve using
polyval.
rain = polyval(a, day);
% display the estimation
fprintf('The estimated concrete strength: %f\n',rain);
% ask if user wants to continue
contChoice = input('Enter "Y" to enter another day? ','s');
% if user wants to exit, set done to true
if strcmpi(contChoice,'y') == 0
done = true;
end
end
%end of script
Output: