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...

  • java code please 14. Next we'll complete the setValues() method. Instead of giving you exact code...

    java code please 14. Next we'll complete the setValues() method. Instead of giving you exact code I'll tell you what to do. Use other code as a guide.  Start with a for loop with a start of int i = 0  Set the ending point of when i is less than the length of the arr array.  Set the incrementation to increase i by 1 using the unary operator ++.  Within the loop set the arr...

  • (+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...

  • You have been developing a Fraction class for Teacher’s Pet Software that contains several fields and...

    You have been developing a Fraction class for Teacher’s Pet Software that contains several fields and functions. a. Add four arithmetic operators, +, -, *, and /. Remember that to add or subtract two Fractions, you first must convert them to Fractions with a common denominator. You multiply two Fractions by multiplying the numerators and multiplying the denominators. You divide two Fractions by inverting the second Fraction, then multiplying. After any arithmetic operation, be sure the Fraction is in proper...

  • 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...

  • How would i code this in MatLab 3. Write the program, openclasses.m, where you start by...

    How would i code this in MatLab 3. Write the program, openclasses.m, where you start by creating a structured array called class which contains the information in the following table (note: seats should be a single fieldname with a (1x2) array inside it). Class Title Introduction to Engineering Computers in Psychology Writing and Rhetoric Beginning Spanish Introduction to Africana Studies Number Seats (Max, Enrolled) 10111 (45, 32) 20000 (28, 25) 12100 (14, 14) 10101 (19,13) (36, 32) 20082 From this...

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