Question

In: Computer Science

Reuse the code to prompt the user for a specific day, test whether it is within...

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);

Solutions

Expert Solution


% 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:


Related Solutions

This code needs to be in C++, please. Step 1: Add code to prompt the user...
This code needs to be in C++, please. Step 1: Add code to prompt the user to enter the name of the room that they are entering information for. Validate the input of the name of the room so that an error is shown if the user does not enter a name for the room. The user must be given an unlimited amount of attempts to enter a name for the room. Step 2: Add Input Validation to the code...
Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the...
Create in C++ Prompt the user to enter a 3-letter abbreviation or a day of the week and display the full name of the day of the week. Use an enumerated data type to solve this problem. Enumerate the days of the week in a data type. Start with Monday and end with Friday. Set all of the characters of the user input to lower case. Set an enumerated value based on the user input. Create a function that displays...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
There is error in this java code. Pls debug. // Prompt user for value to start...
There is error in this java code. Pls debug. // Prompt user for value to start // Value must be between 1 and 20 inclusive // At command line, count down to blastoff // With a brief pause between each displayed value import java.util.*; public class DebugSix3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String userNumString; int userNum, val; final int MIN = 1; final int MAX = 20; System.out.println("Enter a number between " +...
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome...
provide a JavaScript code that finds if the given word by user (prompt) is a Palindrome or no.
C++ code a program should prompt the user for the name of the output file. The...
C++ code a program should prompt the user for the name of the output file. The file should be opened for write operations. Values calculated by the program will be written to this file. The program must verify that the file opened correctly. If the file did not open, an error message should be printed and the user should be prompted again. This should continue until the user supplies a valid filename.
Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT