Answer:
MATLAB CODE:
clc;
clear all;
x=[1 2 3 4]; %Input vector of variable size
[gm,ra,hm]=arm_prop(x) %Main function calling , output values are hm, ra, hm and imput is x
%% Main function
function [gm,ra,hm]=arm_prop(x)
[gm]=geo_mean(x); %Calling Sub function 1
[ra]=rms_avg(x); %Calling Sub function 2
[hm]=har_mean(x); %Calling Sub function 3
%Sub function 2 =Rms average
function [gm]=geo_mean(x)
n=numel(x); %calculating number of elemnts in vector x
temp=1; %Temporary value for multiplying each and every value of x
for i=1:1:n % For loop run for number of elements in x
temp=temp*x(i); %Multliplyng each and every element of x
end
gm=temp^(1/n); % Calculating geometric mean
end
%Sub function 2 =Rms average
function [ra]=rms_avg(x)
temp=0; %Temporary value for adding square of each and every value of x
N=numel(x); %calculating number of elemnts in vector x
for i=1:1:N % For loop run for number of elements in x
temp=temp+x(i)^2; %Adding square of each and every element of x
end
ra=(temp/N)^(1/2); % Calculating Rms average
end
%Sub function 3 =Harmonic mean
function [hm]=har_mean(x)
temp=0; %Temporary value for adding reciprocal of each and every value of x
N=numel(x); %calculating number of elemnts in vector x
for i=1:1:N % For loop run for number of elements in x
temp=temp+(1/x(i)); %Adding sreciprocal of each and every element of x
end
hm=N/temp; % Halculating Harmonic mean
end
end
Results:
gm =
2.2134
ra =
2.7386
hm =
1.9200
Here in one main function. 3 sub functions are written. Every sub function returns one output. As all 3 sub functions are inside main function, main function returns 3 output values gm, ra, hm.
Step-by-step explanation: