Question

MATLAB Part 1 – randFloatValue.m This function accepts two numbers, lower and upper, and returns a...

MATLAB

Part 1 – randFloatValue.m This function accepts two numbers, lower and upper, and returns a random number in between. The rand() function will be useful here.

Part 2 – getValue.m getValue has three parameters: - prompt: A string that is displayed to the user. This should be passed to your input function. - lower: The lowest number that the user is allowed to input - upper: The highest number that the user is allowed to input This function should pass the prompt (which is a string such as ‘enter a number between 1 and 10’) to the input function. Then determine whether the number that the user entered is between lower and upper, inclusive of lower and upper. If it is not, then ask the user again until a valid number is entered.

Part 3 – getFile.m This function should ask the user to enter a file name (remember the ‘s’ flag with your input function). It should then check to make sure that the file ends in .txt. You will need to use the strcmp function to determine this. Then, if the file name does not end in .txt, the user should be asked until they enter a valid file name.

Part 4 – calcBounds.m calcBounds has two parameters: - a_rate: Rate to be used in the simulation. - var: The percentage that a_rate may vary. This function should calculate two things: - lower_bound: a_rate – variation_amount - upper_bound: a_rate + variation_amount Keep in mind that variation_amount is not the same as var. var is the percentage variation from a_rate for lower_bound and upper_bound. variation_amount is the actual amount that lower_bound and upper_bound differ from a_rate. To find variation_amount, we can multiply a_rate by var/100. We need to divide var by 100 because we need the fraction as a decimal number instead of a percentage. Apply this to your calculations for the upper and lower bounds.

Part 5 – writeFile.m writeFile.m has 4 parameters: - filename: the name of the file that we will be writing to - num_sim: the number of simulations that we want to write to the file - lower: the lowest number of attackers possible - upper: the highest number of attackers possible The algorithm for this function goes as follows: 1. Open the file using filename, with write access. 2. Loop num_sim amount of times 3. Inside each loop iteration, generate a random number using your randFloatValue function. The bounds for randFloatValue are lower and upper. 4. Inside each loop iteration, use fprintf to write the generated random number to the file 5. Close the file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

Sample output:

Code to copy:

% randFloatValue.m

function r=randFloatValue(lower,upper)

    % find a random value between lower and upper

    r=lower+(upper-lower)*rand(1);

end

Program:

Sample output:

Add a comment
Know the answer?
Add Answer to:
MATLAB Part 1 – randFloatValue.m This function accepts two numbers, lower and upper, and returns a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Write a function file_copy() that takes two string parameters: in file and out_file and copies...

    2. Write a function file_copy() that takes two string parameters: in file and out_file and copies the contents of in_file into out file. Assume that in_file exists before file_copy is called. For example, the following would be correct input and output. 1 >>> file_copy( created equal.txt', 'copy.txt) 2 >>> open fopen ( copy.txt') 3 >>> equal-f = open( 'created-equal . txt') 4 >>equal_f.read () 5 'We hold these truths to be self-evident, Inthat all men are created equalIn' 3. Write:...

  • Problem: Create a program that contains two functions: main and a void function to read data...

    Problem: Create a program that contains two functions: main and a void function to read data from a file and process it. Your main function should prompt the user to enter the name of the file (Lab7.txt), store this name, and then call the function sending the name of the file to the function. After the function has completed, the main function should output the total number of values in the file, how many of the values were odd, how...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Purpose of it is to coordinate the interaction between the user and the lower-level functionality of...

    Purpose of it is to coordinate the interaction between the user and the lower-level functionality of the game. There are two overloaded constructors, one for constructing a brand new game and one for constructing a game from a file. w - Move Up    s - Move Down    a - Move Left    d - Move Right    q - Quit and Save Board If the user inputs any one of these characters, execute the corresponding move. This should result in a refreshed...

  • I'm a bit confused on how to get this program to run right. Here are the...

    I'm a bit confused on how to get this program to run right. Here are the directions: Part 1: Write a Python function called reduceWhitespace that is given a string line and returns the line with all extra whitespace characters between the words removed. For example, ‘This line has extra space characters ‘  ‘This line has extra space characters’ Function name: reduceWhitespace Number of parameters: one string line Return value: one string line The main file should handle the...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • Problem 3 Write a function named repeat_words that takes two string parameters: 1. in_file: the name...

    Problem 3 Write a function named repeat_words that takes two string parameters: 1. in_file: the name of an input file that exists before repeat_words is called 2. out_file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than...

  • PYTHON 4. Define a function that takes two arguments: a string called strText and a number...

    PYTHON 4. Define a function that takes two arguments: a string called strText and a number called intNumber. This function will use a repetition structure (a While or For loop) to print strText intNumber of times. Call this function. 5. Get an input from the user that is a file name with an extension (e.g., "myfile.ipynb" or "myfile.txt"). Print only the characters that follow the "." in the file name (e.g., "ipynb" and "txt"). 6. Ask the user for 5...

  • Using python 1. Write: A program that implements a logbook, recording the visitors to a place...

    Using python 1. Write: A program that implements a logbook, recording the visitors to a place of interest and their visit's purpose. This log book could later be read by another program. Implement a function called log that takes one parameter, filename, the name of a file. You may assume the file is in the current working directory of the program. log should prompt the user for their name arid the nature of their visit. log should then append a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT