%Andrew McCallum %Problem Set 11 %Nov. 12, 2007 %Question 2 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 m = 100; 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)