# [MATLAB] Write a function called myMultProd.m that computes thecumulative product of the elements in

[MATLAB] Write a function called myMultProd.m that computes thecumulative product of the elements in a vector. The cumulativeproduct, pj, of the jth element of the vector x, xj, is defined bypj = (x1)(x2) … (xj) for j = 1:length of the vector x. For example,when you run your function it should look like this: >> x =[2 3 4 2]; >> myMultProd(x) >> ans = 2 6 24 48 That is,the function returns: 2, 2*3, 2*3*4, 2*3*4*2 where 2 is p1, 2*3 isp2, 2*3*4 is p3, etc. a) Do this first using two for loops to explicitly carry out thecalculation element-byelement. The inner loop should accumulate theproduct and the other loop should move through the elements of thevector p. b) Write a line of code to replace (but do not actually remove,see next part of the problem) the entire inner for loop by usingthe prod function. c) Add another argument to myMultProd which can either be a 1 ora 2. If it’s a 1, use the procedure in part (a). If it’s a 2,instead use the single line of code from part (b). So now your codeshould work like this: >> myMultProd(x,2) The output shouldbe the same for both methods. You can check to make sure the outputis correct by using the cumprod function, which does the same thingas the function you just wrote. d) Add checks to your function that produce error or warningmessages to make sure that: – the input vector is a vector of numbers and not any other datatype – that the numbers in the vector are real (and notimaginary) – the input vector is not a matrix – if the input vector is anempty array, then the output should also be an empty array – the second input is a 1 or 2 Attached 