Question

For this In-Class Exercise, you are asked to build a MATLAB code that makes a few...

For this In-Class Exercise, you are asked to build a MATLAB code that makes a few assignment statements and a logical test with random numbers. To answer this ICE, you will need to upload a screenshot of your successful run showing ALL of the outputs. Remember to use good programing skills for the code. For your outputs:

If your output for a step below is a single value, use a command similar to:fprintf(‘Question 5 answer: %4.3f \n,A) or fprintf(‘Question 5 answer: %d \n,A)

If your answer is a vector or an array, use a normal print by leaving off the semicolon like:A = 1:3 Questions: PLEASE ONLY ANSWER 5-8 in MATLAB CODE FORMAT

1. Assign a random floating point number between 0 (inclusive) and 1 (exclusive) to the variable A.

2. Assign a random floating point number between 0 (inclusive) and 5 (exclusive) to the variable B.

3. Assign a random integer between 1 (inclusive) and 5 (inclusive) to the variable C.

4. Assign a random integer between 11 (inclusive) and 50 (inclusive) to the variable D.

5. Assign a random floating point number to EACH element in a 3x3 array between 0 (inclusive) and 1 (exclusive) to the variable E.

6. Assign a random integer to EACH element in a 3x3 array between 0 (inclusive) and 10 (inclusive) to the variable F. [TRICKY QUESTION]

7. Assign a random floating point number between 0 (inclusive) and 1 (exclusive) to the variable G THEN test ‘G’ to see if it is greater than 0.6. IF G is great than .6 display “G is greater than 0.6” and if G is less than 0.6 display “G is less than 0.6” and if G equals 0.6 display “G equals 0.6”. [HINT: Remember the “disp” command??]

8.The "rand" function uses what type of distribution?

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

Question 1:

A = rand();

fprintf( 'Question 1 answer : %f ',A);

%default range of rand( ) is o and 1

Question 2 :

x = 0 ; y= 5;

B = (y - x ) * rand ( ) + a

fprintf( 'Question 2 answer : %f ',B);

%To change the range of the distribution to a new range, (x, y), multiply each value by the width of the new range, (yx) and then shift every value by a.

Question 3:

C = randi ( [1 5],1,1)

fprintf( ' Question 3 answer : %d ',C);

%syntax, randi([imin imax],m,n)

Question 4 :

D = randi ( [11 50] , 1,1);

fprintf('Question 4 answer : %d',D);

Question 5 to 7

1 question 5 2 default range of rand is (0,1) rand (3) 3Е 4 disp ( Question 5 ,E : ); 5 disp (E) 6 %question 6 7 range is 0

OUTPUT

Question 5 ,E : 0.926747 0.678660 0.105744 0.070970 0.479479 0.314386 0.735128 0.649900 0.919798 Questin 6 2 6 3 5 1 6 10 3 Q

RAW CODE :

%question 5
%default range of rand is (0,1)
E = rand(3);
disp(' Question 5 ,E : ');
disp(E)
%question 6
%range is 0 to 10 and size 3*3
F = randi([0 10],3,3);
disp(' Questin 6 ,F : ');
disp(F)

%question 7
G = rand();
disp('Question 7 : ');
%checking conditions
if(G>0.6)
disp('G is greater than 0.6');
elseif(G<0.6)
disp('G is less than 0.6');
else
disp('G equals 0.6');
end

Question 8 :

rand returns normalized values (between 0 and 1) that are drawn from a uniform distribution.

Use :

help('rand')

Add a comment
Know the answer?
Add Answer to:
For this In-Class Exercise, you are asked to build a MATLAB code that makes a few...
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
  • For this In-Class Exercise, you are asked to build a MATLAB code that makes a few...

    For this In-Class Exercise, you are asked to build a MATLAB code that makes a few assignment statements and a logical test with random numbers. To answer this ICE, you will need to upload a screenshot of your successful run showing ALL of the outputs. Remember to use good programing skills for the code. For your outputs: If your output for a step below is a single value, use a command similar to:fprintf(‘Question 5 answer: %4.3f \n,A) or fprintf(‘Question 5...

  • Write a MATLAB code to generate an array of 100 random integers between 1 and 10...

    Write a MATLAB code to generate an array of 100 random integers between 1 and 10 using the command “randi”. Using “if” statement, impose the condition that if a number in the array is greater than 5, the number is modified as, number = number – 11. Find the sum of the array and store it. Repeat this exercise for 10, 1000 and 100000 trials and plot the following: (a) Sums obtained vs trails number (b) Histogram of the sum...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

  • Use LabView instead of matlab please Expert Q&A Done Create a VI that: Generates random integers...

    Use LabView instead of matlab please Expert Q&A Done Create a VI that: Generates random integers between 0 and 40. Iterate this random process until the random integer equals 13. Display the following non the Front panel (1.) The actual random number (2.) The iteration number Include a time delay so the user can watch the valuse update as the program executes. USE MATLAB

  • Assignnment #1 Your Very First C++ Program Write a C+program to achieve the followings. Start a new line for each...

    Assignnment #1 Your Very First C++ Program Write a C+program to achieve the followings. Start a new line for each output a. Declare an integer and assign it with a value 45876 b. Prompt the user to input a floating point number of value 345.24681359 Display the message "Welcome to the 2019 EECE 4272 Summer Class!" c. d. Display the number from part (a) with the following format: () fixed floating-point number, (i) 2 digits after the decimal point, (ii...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • 1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers...

    1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...

  • Matlab Code: You will have to read in firing inputs from a user (angle and power)....

    Matlab Code: You will have to read in firing inputs from a user (angle and power). Prior to doing this, you should report out to the user via the command window the current wind speed and direction. For the value of wind speed, you can use a random number with magnitude range from -25 to 25 mph where -25 is wind blowing toward the left and +25 is wind blowing to the right. Note you can generate a random number...

  • photo of the code please and an explnation if possible, Construct a simple MATLAB function program...

    photo of the code please and an explnation if possible, Construct a simple MATLAB function program my_factorial which calculates product of first n positive integer numbers (i.e. find factorial n!). For full points: - Make sure you protect the code from illogical use (n must be positive integer) - Test the function by comparing with built in MATLAB function factorial(n) - Make sure you test your function for any limitations. O marks) -3. Using my factorial function from the previous...

  • In this exercise, you will create a script called if_then_else.sh that uses an IF THEN ELSE...

    In this exercise, you will create a script called if_then_else.sh that uses an IF THEN ELSE statement. The if_then_else.sh script will Use one command line argument, which will be a number between 1 and 10 Assign the value of the first argument to a local variable called NUM. HINT: Look at line 5 in the example screenshot for arguments.sh Use one IF THEN ELSE statement to compare the value of NUM If the number is less than 5, display the...

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