M = 1000000;
x = normrnd(0,1,1,M);
y = sqrt(2*pi)*cos(x);
thetahat = mean(y)

  %Simulering fra N(0,1)
Sy = sqrt(var(y))
CI = [thetahat - 2*Sy/sqrt(M);thetahat + 2*Sy/sqrt(M)]

  %Simulering fra N(0,sigma)
sig =0.9;
x = normrnd(0,sig,1,M);
y = sqrt(2*pi)*cos(x).*normpdf(x,0,1)./normpdf(x,0,sig);
thetahat = mean(y)
Sy = sqrt(var(y))
CI = [thetahat - 2*Sy/sqrt(M);thetahat + 2*Sy/sqrt(M)]
