BENG 449 Problem 2 4

# BENG 449 Problem 2 4 - sqr_diff = 0; for i = 1:n sqr_diff =...

This preview shows page 1. Sign up to view the full content.

2/7/08 6:48 PM MATLAB Command Window 1 of 1 >> % BENG 449 -- Problem Set 2, Question 4 % Written by Alex Lemon disp([' ']); % Create a random vector X with 20 elements from the uniform % probability distribution on (0,1). n = 20; X = zeros(1, n); for i = 1:n X(i) = rand(); end % 1.) Compute the sample mean % 1A.) Using the definition of sample mean sum_x = 0; for i = 1:n sum_x = sum_x + X(i); end x_bar = sum_x / n; disp(['Using the formal definition, the sample mean of X is ', . .. num2str(x_bar)]); % 1B.) Using Matlab's built-in function disp(['Using the built-in function, the sample mean of X is ', . .. num2str(mean(X))]); % 2.) Compute the sample variance % 2A.) Using the definition of sample variance
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sqr_diff = 0; for i = 1:n sqr_diff = sqr_diff + (X(i) - x_bar)^2; end samp_var = sqr_diff / (n - 1); disp(['Using the formal definition, the sample variance of X is ', . .. num2str(samp_var)]); % 2B.) Using Matlab's built-in function disp(['Using the built-in function, the sample variance of X is ', . .. num2str(var(X))]); Using the formal definition, the sample mean of X is 0.46457 Using the built-in function, the sample mean of X is 0.46457 Using the formal definition, the sample variance of X is 0.11004 Using the built-in function, the sample variance of X is 0.11004 >>...
View Full Document

## This note was uploaded on 07/19/2008 for the course BENG 449 taught by Professor Richardcarson during the Spring '08 term at Yale.

Ask a homework question - tutors are online