Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Matlab function named \"Team#Hw3ABPT, to calculate the standard deviati

ID: 3881413 • Letter: C

Question

Create a Matlab function named "Team#Hw3ABPT, to calculate the standard deviation of the given sample of data, using the equation where, y- a vector from 0 to 2 n = total number of elements in vector x and y average value ofy The input to the Matlab function should be the total number of elements (n) in x and y, while the output should be the standard deviation of the sample data. Within the Matlab function Create vector x using linspace and n number of elements Compute vector y using the above-mentioned relation. Calculate the average using the inbuilt function available in Matlab Sum((w-)2). Calculates using the provided formula in Eq.[8] . Attempt to execute the Matlab function for" = 100, 1000, 10000, 100,000 Note the convergence of the solutions (less difference between each run) and the increased run time Copy the code in function file as well as the inputs created, and outputs generated in the command window in the Word document under the heading Part 7.Clearly indicate the function and the inputs as well as the outputs from the command window

Explanation / Answer

Note :

The name of matlab function cannot contain character like '#', that's why the function name has been changed to Team_HW3AB_P7

Matlab code :

function std_dev = Team_HW3AB_P7(n)
% n is the input => no. of elements in x
% output will be std_dev

tic % used for finding the time required to run this code
x = linspace(1, n, n); % creating vector from 1 to n
y = x.^2;
avg = mean(y); % calculating average
s = sqrt(sum((y-avg).^2)/(n-1)); % finding std. deviation
std_dev = s;
toc % used for finding the time required to run this code
end

Sample output :

Team_HW3AB_P7(5)

Elapsed time is 0.134455 seconds.

ans =

9.6695

Observation :

While running this matlab code for n = 100, 1000, 10000, 100000, we observed that the run time increased.