Question: Most programming languages do not support operations on arrays like MATLAB does. Write a MATLAB program that will implement the equivalent of an element by

 Most programming languages do not support operations on arrays like MATLABdoes. Write a MATLAB program that will implement the equivalent of an

Most programming languages do not support operations on arrays like MATLAB does. Write a MATLAB program that will implement the equivalent of an element by element multiply operation z=x.*y for 1D row arrays using iteration and scalar operations. Your program should also calculate the summation of the total = Loker xy using a loop and assign the result to total. This will allow the program to later be ported to C++ or JAVA. In other words, the program should multiply the corresponding elements of two 1D row arrays and produce a 1D row array, named z, of the same length but performed using iteration and scalar operations instead of an element by element operation. Test the program for the following two test cases: X = [5]; and y = [1]; x = [5, 4, 1, 4]; and y = [1, 0, 2, -1]; Add inline error handling to the program to ensure that the arrays are the same length. If the arrays are not the same length, the operation should not be performed and instead a message indicating the lengths are incompatible displayed. Test the program for the original test cases plus a case that checks the inline error handling. For MATLAB grader, we will use random vector x and y 1 %Generate random test vector x and y of length n 2 n = randi([1 7]) 3 x=randi([0 9],1,n) 4 y=randi([09],1,n) 5 6 %Handling errors - use length function to check if your vector is of the same length 7 if (1) %replace the "1" with your own condition to check if the two vector is of the same length, use the length function to check 8 9 %Create a result array z that is filled with o of the same length of x initially, then fill with the x*y in your loop for each of the element. z=zeros(1,n); 10 11 12 %initialize total total =0; 13 14 15 % do the calculation using a loop (for or while loop) %assign **y to z and calculate the total using a loop, 16 17 18 19 else disp("Vector x and y must be the same length") 21 end 20 22

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!