%Andrew McCallum %Problem Set 11 %Nov. 12, 2007 clc; clear; close all; %Increase the display precision of my variables. format('long','g'); %1.a. %Bernoulli draws are Binomial draws where nn = 1 nn = 1; p = 0.52 %matrix dimensions: %for question 3bern; results = 9999*ones(7,4); for i = 1:1:7; m = 10^i; n = 1; %Bernoulli draws rand('seed',0); x = binornd(nn,p,m,n); %1.b. Closed form MLE for Bernoulli is phat = xbar; p1b = mean(x) %1.c. %There are a few good examples of how to set up a uni- or multivariate %function without using sperate files at the end of question 1.c. Agrawal %and I did the first question from Pset 10 using only inline functions. See the %file Pset10Q1_inline.m. %X0 is the initial value for r. Since we aren't minimizing w.r.t. to xbar %or m we don't need initial values for them. x0 = 0.1; xbar = mean(x); p1c = fminsearch(@(r) lnbernoulike(r,x), x0) %1.d. %Solve the FOC. fsolve sets a function equal to zero and solves it w.r.t %the variable following the @ symbol. p1d = fsolve(@(r) lnbernoufoc(r,x),x0) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %3.Bernoulli results(i,1) = i; results(i,2) =p1b; results(i,3) =p1c; results(i,4) =p1d; end % %A short example for how to set up a univariate function without using % %seperate files: % sqr = @(x) x.^2 + 3.*x; % fplot(sqr, [-4,4]); % xmin = fminsearch(sqr,10); % %A multivariate example: % parabl = @(x,y) x.^2 + y.^2; % [X,Y] = meshgrid(-8:0.5:8); % Z = parabl(X,Y); % mesh(X,Y,Z,'EdgeColor','cyan');