Vectorize this code Write one assignment statement that will
Vectorize this code! Write one assignment statement that will accomplish exactly the same
thing as the given code (assume that the variable vec is a vector and it has been initialized):
newv = zeros(size(vec));
myprod = 1;
for i = 1:length(vec)
myprod = myprod * vec(i);
newv(i) = myprod;
end
newv % Note: this is just to display the value
Solution
the following code will multiply the value of vec from position 1st to position nth . Hence the problem statement is
Problem statment : Assume that you have a matrix of order 1xn say vec. intiallise it with some value . now u have to generate an onother matrix of same order whose pth position has value equal to the multiplication of all number in vec upto pth location starting from 1st position. for example newv(4)=vec(1)*vec(2)*vec(3)*vec(4)
