Write a function average that takes an input vector .x and returns as output the
ID: 3668607 • Letter: W
Question
Write a function average that takes an input vector .x and returns as output the average (mean) value of its elements, according to the formula average(x) = 1/N summation ^N _ I = 1 xi where N is the number of elements in x. Test your function by comparing its output to the output of the built-in Matlab function mean on a random vector of length 100 whose elements are uniformly distributed between 0 and 1. Write a function deviation that takes an input vectors and returns the standard deviation of its elements, according to the formula deviation (or) = .square root 1/N summation ^N _i= (x_i - X)^2 where x is the average the elements of .r, and N is the number of elements in x. Test your function by comparing its output to the output of the built-in Matlab function std on a random vector of length 100 whose elements are in a normal (Gaussian) distribution about x = 0.Explanation / Answer
AVERAGE:
sum=0;
num=0;
ValuesEntered=[];
while(1)
n=input('Enter number >=0, enter ends input and finds average ->');
if (n>=0)
sum=sum+n;
num=num+1;
ValuesEntered=[ValuesEntered n]
else
Average=sum/num
break
end
end
*********************************
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.