clc clear all disp('ABSTRACT') disp(' To find the average and standard deviation of numbers') % PURPOSE: Average and standard deviation of numbers % Chapter 22 - EXERCISE 7 %% INPUTS disp(' ') disp('INPUTS') % x is the row vector of numbers x =[1 4 6 8 19]; disp(' The input numbers are:') disp(x') %% CODE % length gives the number of elements in the x vector n =length(x); % Calculating the numerator for the mean sum3=0; for i=1:1:n sum3=sum3+x(i); end % Calculating the average from the formula avg =sum3/n; % Standard deviation calculations % Calculating the numerator of the standard deviation sum4=0; for i=1:1:n sum4=sum4+(x(i)-avg)^2; end % Calculating the standard deviation stdev=sqrt(sum4/(n-1)); %% OUTPUTS disp('OUTPUTS') fprintf(' The average of the numbers is %g\n',avg) fprintf(' The standard deviation is %g\n\n',stdev)