Question

In: Computer Science

Using MATLAB or Octave, use documenting code to Write a script that prompts the user for...

Using MATLAB or Octave, use documenting code to Write a script that prompts the user for a minimum and maximum real number, then generates and prints a random number in the requested range. The script should then do the same for an integer range. Sample output: Enter a minimum real value: 0.5 Enter a maximum real value: 30 A random number in the range ( 0.5000, 30.0000 ) is 1.7851 Enter a minimum integer value: -10 Enter a maximum integer value: 20 A random integer in the range [ -10, 20 ] is 8 Enter a minimum real value: -5 Enter a maximum real value: 5 A random number in the range ( -5.0000, 5.0000 ) is -4.5644 Enter a minimum integer value: 50 Enter a maximum integer value: 75 A random integer in the range [ 50, 75 ] is 65

Solutions

Expert Solution

Please find the required MATLAB scripts:

For real numbers:

%========================================================================

clear all;
clc;

min_real_val = input('Enter a minimum real value: ');
max_real_val = input('Enter a maximum real value: ');
num_real_rand = min_real_val+(max_real_val-min_real_val)*rand;
fprintf('A random number in the range ( %f, %f ) is %f\n',min_real_val,max_real_val,num_real_rand);

%========================================================================

For integer numbers:

%========================================================================

min_int_val = input('Enter a minimum integer value: ');
max_int_val = input('Enter a maximum integer value: ');
num_int_rand = randi([min_int_val,max_int_val]);
fprintf('A random integer in the range [ %d, %d ] is %d\n',min_int_val,max_int_val,num_int_rand);

%========================================================================

Sample output:

Enter a minimum real value: 0.33
Enter a maximum real value: 1.7
A random number in the range ( 0.330000, 1.700000 ) is 0.524384

Enter a minimum integer value: -10
Enter a maximum integer value: 40
A random integer in the range [ -10, 40 ] is 11

Hope this helps!

************* PLEASE THUMBS UP!!!!!!!! *************

In case of any clarification, please comment!


Related Solutions

Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval...
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval and stores it in a variable named Lbound - an upper-bound for the plot interval and stores it in a variable named Ubound, and - the number of points at which a function is to be evaluated to generate a plot of the function over the specified range and stores it in a variable named npoints. • Generates a plot of f(x) = x3...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they...
(Using Matlab) and "while" function 1.   Write a program that prompts the User for if they would like to enter a real number. If yes, prompt the User for the real number. Continue to do this until the User enters “no” to the first question. After the User enters “no”, display the average of all the numbers entered. (Using Matlab) and "while" function 2.   Write a program that prompts the User for if they would like to enter a real...
Write a script that prompts the user for a pathname of a file or directory and...
Write a script that prompts the user for a pathname of a file or directory and then responds with a description of the item as a file along with what the user's permissions are with respect to it (read, write, execute).
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
script for Secant Method. Using Matlab or Octave. The data: y = x.^2 - 1.2 x_lower...
script for Secant Method. Using Matlab or Octave. The data: y = x.^2 - 1.2 x_lower = 0.4 x_upper = 0.6 Es = 0.5*10^(2-n) n = 5
MATLAB Write a script which asks the user of the program to provide an initial horizontal...
MATLAB Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what...
Write a program/code that prompts the user for a minimum min and a maximum max. Then...
Write a program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. (WRITTEN IN C) For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
Write C++ code that prompts the user for a username and password (strings), and it calls...
Write C++ code that prompts the user for a username and password (strings), and it calls the login() function with the username and password as arguments. You may assume that username and password have been declared elsewhere. Your code should print error messages if login() generates an exception: LoginException: "Username not found or password incorrect" ServerException: "The login server is busy and you cannot log in" AccessException: "Your account is forbidden from logging into this server" Any other exception: "Unknown...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT