In: Computer Science
USING MatLab (Arrays)
This is a fairly simple problem for arrays in MATLAB. The code for the question with comments is given below -
%Set ASIZE to 5
ASIZE = 5;
%Create array of size ASIZE
arr = zeros(1,ASIZE);
for i=1:ASIZE
arr(i) = input('Enter value: ');
end
%Sum of all array elements
arraySum = sum(arr)
%Product of all array elements
arrayProduct = prod(arr)
%New array by doubling all array elements
newArr = arr*2
This code is for all the parts. You can remove any statement if you want to cater to your question.
The MATLAB inbuilt functions sum and prod are used to calculate the sum and product of the array elements. Multiplying the array with 2 directly doubles all the values of the array.
Code Screenshot -
OUTPUT Screenshot -