Question: Mathlab Task 1 Write your own function mfile that accepts two row vectors, A and B , as inputs and produces the following outputs .

Mathlab

Task 1

Write your own function mfile that accepts two row vectors, A and B, as inputs and produces the following outputs. Save your function mfile as task1.m

  • A scalar that gives the number of elements in B that are greater than the mean of the elements in A.
  • A column vector of all the prime numbers that lie between the minimum value in A and the maximum value in B.
  • A two element row vector in which the first element is the number of prime numbers between min(A) and max(B) that are also greater than the mean of the elements in A. The second element in this vector is the sum of these primes.

Next write a script mfile to test your function for the following cases. Save your script file as ScriptTask1.m. Be sure to assign all three outputs to target variables with unique descriptive names in each of the function calls. This practice is to ensure that all of your results are stored in the base workspace. Make sure to include help comments in your script mfile as well.

Test case 1: A = [12 9 3 2 25]; B = [1 6 20 4 5 15 12];

Answers for case 1 should be

out1 = 3 %There are 3 elements in B greater than the average of A which is 10.2.

out2 = [2 3 5 7 11 13 17 19] %These are the primes between min(A) = 2 and max(B) = 20.

out3 = [4 60] %Four of the primes in are greater than mean(A) and their sum is 60.

Test case 2: A = [3:3:99]; B = [4:4:44];

Test case 3: A = [100:-2:50]; B = [60:70];

Test case 4: make up your own

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!