Question

Write a script file that will compare entries in vector V to entries in vector M...

Write a script file that will compare entries in vector V to entries in vector M and determine how many entries in V are greater than the same entry in M, equal to the same entry in M, and less than the same entry in M. For example, V(1) is 7 and M(1) is 6, thus for this entry, V is greater than M.

V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7]

M = [6 4 3 -2 3 -9 -1 3 7 -2 2 -9]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
V = [7 9 -8 9 3 -8 -5 1 10 10 0 -7]
M = [6 4 3 -2 3 -9 -1 3 7 -2 2 -9]
increase_count = 0;
decrease_count = 0;
no_change_count = 0;
for i=1:length(V)
    if V(i) < M(i)
        increase_count = increase_count+1;
    elseif V(i) > M(i)
        decrease_count = decrease_count+1;
    else
        no_change_count = no_change_count+1;
    end
end
fprintf("Number of times entries in V are greater than the same entry in M is %d\n", increase_count)
fprintf("Number of times entries in V are smaller than the same entry in M is %d\n", decrease_count)
fprintf("Number of times entries in V are equal to the same entry in M is %d\n", no_change_count)

Add a comment
Know the answer?
Add Answer to:
Write a script file that will compare entries in vector V to entries in vector M...
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
  • Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8...

    Question 1 a. Define the following matrices in a script file (M-file), ? = ( 8 9 10 11; 23 9 16 15 ;11 12 3 6; 1 2 8 9 ) ? = ( 2 21 7 15; 12 4 8 22; 23 9 5 13; 23 4 21 22) ℎ = (4 9 12 15) b. Add suitable lines of codes to the M-file to do the following. Each of the following points should be coded in only...

  • S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write...

    S.A vector IS givell by [5, 17,-3, 8, 0,-7, 12, 15, 20,-6, 6, 4,-7, 16]. Write a program as a 3 or 5, and, raises to the power of 3 the elements that are script tile that doubles the elements that are positive and are divisible by negative but greater than -5. following values. The value of each element in the first row is the number of the 6. Write a program in a script file that creates an matrix...

  • Projection vector, p, of w on V V = (6,6) p = (4.4) W = (6,2)...

    Projection vector, p, of w on V V = (6,6) p = (4.4) W = (6,2) 1 2 3 4 5 6 Visualising vector projection Exercise 2 The projection of w= is given by the projection formula below: Plot all three vectors using plot and make the projection vector pa dashed line. Write a script from scratch to produce the figure below (click to enlarge). Make sure the axes are equal. Show/hide hint Optional extra challenge Upload your M-file that...

  • MATLAB Define the following computer programming terms and give an example of each. MATLAB example Sequence...

    MATLAB Define the following computer programming terms and give an example of each. MATLAB example Sequence Selection structure- Repetition structure - Relational operators (True = 1, False = 0) Logical operators (True = 1, False =0) And Or Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to Not ans ans Type the following relational operator commands into MATLAB in the command window one at a time. Write the results to...

  • mathlab Q2. Write a script file that accepts the user input of array of any size...

    mathlab Q2. Write a script file that accepts the user input of array of any size then uses nested for loops to find the minimum and maximum elements in the array. See slides 43,44 & 45 for hints Use the following 2 arrays to test your script: A- A 10 10 -4 17 2 5 0 13 -7 9 AND لیا M -1 5 -7 4 7 17 6 9 10 Sample Outputs: For the given array, the min. value...

  • provide a python script please For the following vectors and matrices, using the NumPy library, write...

    provide a python script please For the following vectors and matrices, using the NumPy library, write a script file that determines the solution for x given by the equation x-(A AT)b-Cd where AT denotes the transpose of A 1 2 3 4 16 12 8 4 A-2 4 6 8 3 6 9 12 4 8 12 16 C-12 9 6 3 8 6 4 2 4 3 2 1 4 The output to the command terminal prompt within Spyder...

  • Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix...

    Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix algebra: A vector is a one-dimensional set of numbers, such as [42 9 20]. The dot product of two equal-length vectors A and B is computed by multiplying the first entry of A by the first entry of B, the second entry of A by the second entry of B, etc., and then summing these products. For example, the dot product of [42 9...

  • Please use Matlab to solve and show your full codes Write a script file Ask the...

    Please use Matlab to solve and show your full codes Write a script file Ask the user to enter sides of a triangle: a, b, c Check to see if the sides are all greater than 0 If they are: Use the function (triangle) that you created in your last homework problem (HW#5 problemttF) to calculate the area. command Display the results on the screen using fprintf write the results to disk using the fprintf command. If any of the...

  • WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V 1.)INITIALIZE THE VECTOR, V, WITH...

    WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V 1.)INITIALIZE THE VECTOR, V, WITH 10 INTEGERS WITH VALUES FROM 1 TO 10 2.)OUTPUT THE VECTOR IN DESCENDING ORDER, THEN ASCENDING ORDER 2.)ADD ALL THE EVEN NUMBERS 3.)ADD ALL THE ODD NUMBERS 4.)OUTPUT THE SUM OF EVEN INTEGERS 5.)OUTPUT THE SUM OF ODD INTEGERS 7.)OUTPUT THE PRODUCT OF EVEN INTEGERS 8.)OUTPUT THE PRODUCT OF ODD INTEGERS SAMPLE: Vector: 2 4 3 5 2 3 8 9 1 10 Ascending...

  • UNIX QUESTION Exercise #1. [8 Marks] Create a script that does the following: a. Takes 4...

    UNIX QUESTION Exercise #1. [8 Marks] Create a script that does the following: a. Takes 4 input parameters b. Using the shell special variables print the following: i. The command you executed ii. First input iii. Second input iv. Third input v. Fourth Input vi. Process Id vii. Total number of input parameters [ by querying the system for it ] Exercise #2. [8 Marks] Creates a script that does the following: a. Takes two input parameters b. Using 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
ADVERTISEMENT