Question

Start with a 1 × 7 vector of random integers in the interval [2, 12]. Test...

Start with a 1 × 7 vector of random integers in the interval [2, 12]. Test if any of these integers are larger than 6. If any are, find the smallest of these and assign it to K. Then test along the following criteria. If K is an even number, set d = 1. If K is odd and smaller than 10 then set d = 2. But if K is odd and larger than or equal to 10, then set d = 3. If none of the initial 7 integers were larger than 6, set d = 4.

Please use MATLAB and good commenting.

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

code:

%%create a vector of 7 elements ranging from 2 to 12
rand_vector = randi([2,12],1,7);
%set k to inf so it becomes largest than any other element
K = inf;
%check for each element in vector
for item = rand_vector
if item > 6 % if K is greater than 6
if K > item % if K is greater than the current element
K = item; %set K as the item
end
end
end
% if after dividing by 2 remainder is 0 number is even
if rem(K,2) == 0
d = 1; %set d as 1
elseif rem(K,2) == 1 %if remainder is 1 number is odd
if K < 10 %if K is less than 10
d = 2; %set d as 2
else %if K is greater than or equal to 10
d = 3; %set d as 3
end
else % if none of the initial integers were larger than 6
d = 4; %set d as 4
end
%display the value of d
disp("the value of d is " + d);

screenshot:

output:

%for any queries ask in comment and upvote if you like the answer :)

Add a comment
Know the answer?
Add Answer to:
Start with a 1 × 7 vector of random integers in the interval [2, 12]. Test...
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
  • 7. For a discrete random variable, the set of possible values is a. an interval of...

    7. For a discrete random variable, the set of possible values is a. an interval of real numbers. b. a set of numbers that is countable. c. a set of numbers that has a finite number of numbers. d. none of the above. 8. Let X be a continuous random variable, then P( X = 0) is a. 0.00001. b. zero. c. can be large in some random variable. d. none of the above. 9. For a discrete random variable,...

  • MATLAB Onramp ASSIGNMENT: 2. Create a 1x15 (1 row, 10 columns) vector of random numbers (use...

    MATLAB Onramp ASSIGNMENT: 2. Create a 1x15 (1 row, 10 columns) vector of random numbers (use randn command “x = randn(1,10)). And do the following: a.Test vector x for elements that are less than 0.2. Assign the output to a variable named y. b.Create a variable z that contains the elements in x that are greater than 0.2. c. Modify vector x such that any value in it less than 0.2 is replaced by value 0.

  • 1) What is the order of error in the series approximation of: Sin(x + h) -...

    1) What is the order of error in the series approximation of: Sin(x + h) - Sin(x) + hCos(x)-h’Sin(x)/2+h'Cos(x16 a) h2 b) h c) d) None of the above 2) For two conformable matrices a(m,n) and b(n,p), the product of the two matrices is given by the equation: a) c =ba b) (ij) Ekalt, k) (k.) c) c = -b'a d) None of the above 3) Regression analysis involves minimizing: a) The sum of the squares c) The sum of...

  • 2. Write a C++ program, that generates a set of random integers and places them in...

    2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...

  • Exercise 1 Write a program that asks the user to enter the seed for a random...

    Exercise 1 Write a program that asks the user to enter the seed for a random number generator. Then the program uses this seed to roll a dice and hence generates two integers corresponding to the faces of each dice. If their sum is odd, the user has two tries to guess the sum. The program gives the user a hint after the first try. Otherwise, the user has three tries to guess the sum. Sample run 1: Enter the...

  • 1. use python List to Dictionary Write a function that has three parameters: a list of...

    1. use python List to Dictionary Write a function that has three parameters: a list of unsorted numbers with no duplicates, a start number, and an end number. This function should return a dictionary with all integers between the start and end number (inclusive) as the keys and their respective indices in the list as the value. If the integer is not in the list, the corresponding value would be None. Example unsorted list: [2,1,10,0,4,3] two numbers: 3, 10 returned...

  • UTJJISHCHILJ JLRU12 IUU Lxam 2(Ch 3 & 5) Math 12 Late Start Test: Exam 2 (Ch 3 & 5) Time This Question: 1 p...

    UTJJISHCHILJ JLRU12 IUU Lxam 2(Ch 3 & 5) Math 12 Late Start Test: Exam 2 (Ch 3 & 5) Time This Question: 1 pt 20 of 20 (4 complete) ► Suppose 6 cars start at a car race. In how many ways can the top 3 cars finish the race? The number of different top three finishes possible for this race of 6 cars is (Use integers for any number in the expression.) Enter your answer in the answer box...

  • est: Test 2 Tin is Question: 1 pt 8 of 27 (7 complete) Solve the equation...

    est: Test 2 Tin is Question: 1 pt 8 of 27 (7 complete) Solve the equation on the interval o so< 2x 4 sin 0+3=1 What are the solutions in the interval Os0 < 2x? Select the correct choice and fill in any answer boxes in your choice below. O A. The solution set is (Simplify your answer. Type an exact answer, using a as needed. Type your answer in radians. Use integers or fractions for Use a comma to...

  • Compute the following problems using Math Lab.   Instructions: Answer All Questions using MATLAB commands. Question 1....

    Compute the following problems using Math Lab.   Instructions: Answer All Questions using MATLAB commands. Question 1. Create a vector of the even whole numbers between 31 and 75. Question 2. Let x [2516] a. Add 16 to each element b. Add 3 to just the odd-index elcments c. Compute the square root of each element d. Compute the square of each element Question 3. Let x 13 268T and y [4 1 3 5] (NB. x and y should be...

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

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