Question: Create array arr using these commands ( type them exactly ) : r n g ( 1 ) arr = 1 8 + 5 *
Create array arr using these commands type them exactly:
arrrandnrandi
Write and call local function CalculateAverage to calculate the average value averA of the array arr.
Mathematically, average is defined as:
sum of all array elements divided by the number of elements
The function CalculateAverage must have arr as input argument and averA as output argument. In the
function, determine the number of elements in the array use length function Then, use for loop to
calculate a sum of all array elements. Divide the sum by the number of elements to find the array average.
Write and call local function CalculateMin to calculate the minimum value minA of the array arr. The
function must have arr as input argument and minA as output argument. In the function, determine the
number of array elements. Initialize minA by assigning it a very large value, eg of positive infinity. Then,
use the for loop to go through all elements of the array arr, one after another. Inside the for loop, use the
ifconstruct to determine whether the current array element is smaller than the value of minA. If it is
make it a new value of minA.
Print the array average and minimum values with digits after decimal point using fprintf; include
description of the variables.
Organize your script in Input, Calculations, and Output sections. Include cleaning commands; provide
comments; suppress intermediate output. Use only those Matlab methods that were described in class.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
