%Andrew McCallum %Problem Set 11 %Nov. 12, 2007 close all; clc; clear; %Increase the display precision of my variables. format('long','g'); %2.a. randn('seed', 1234); % Normal mean = 1 variance = 6 mu = 1; sig2 = 6; sig = sqrt(sig2); %Matrix dimensions resultsmu = 9999*ones(7,3); resultssig2 = 9999*ones(7,5); for i = 1:1:7; m = 10^i; n = 1; x = normrnd(mu,sig,m,n); %2.b. %MatLab divides by (m-1) (sample size minus 1) our closed form MLE estimator %divides by m, hence the difference. sig22b = var(x); xbar = mean(x); sig22bclosed = sum((x - xbar).^2)/m; %2.c. %Get the MLE estimate via numerical methods. %Because theta is now a vector of parameters we need to specify two initial %values for x0. x0 = [0.001, 8.75342]; theta2c = fminsearch(@(theta) lnnormlike(theta,x), x0) ; %2.d. %Solve the system of nonlinear equations for theta a 2 X 1 vector theta2d = fsolve(@(theta) lnnormfoc(theta,x), x0); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %3. Normal resultsmu(i,1) = i; resultsmu(i,2) =theta2c(1,1); resultsmu(i,3) =theta2d(1,1); resultssig2(i,1) = i; resultssig2(i,2) =sig22b; resultssig2(i,3) =sig22bclosed; resultssig2(i,4) =theta2c(1,2); resultssig2(i,5) =theta2d(1,2); end