필터 지우기
필터 지우기

Empty Matrix with Dynamic Fertility Model

조회 수: 2 (최근 30일)
Sarah Schutz
Sarah Schutz 2019년 12월 17일
편집: Ridwan Alam 2019년 12월 17일
Hi all,
I am working on a question to replicate the simuelation portion of this code below. I have already generated the Emax matrix.
The code below is what I have. However, I am just getting a matrix full of 0's. Is there something I am doing wrong here?
simchoice = zeros(1000,20)
%Looping for 1000 women
for i = 1:1000
for t = 1:20
e = normrnd(0 , sqrt(sigma_e_sq),[1000,1])
if t == 1
N = 0
else
N = sum(simchoice(i, 1:(t-1)))
end
inc = alpha(5) + alpha(6) * t
simC_0 = inc - (p_n * N)
simC_1 = inc - (p_n * (N + 1))
simU_0 = simC_0 - (0.5*alpha(1)*simC_0*simC_0) + ((alpha(2) + e)*N) - (alpha(3)*N*N) + (alpha(4)*simC_0* N)
if t < 20
simV_0 = simU_0 + Emax((N+1), (t+1))
end
simchoice((i+1),t) = 0
if N <= 7
simU_1 = simC_1 - (0.5*alpha(1)*simC_1*simC_1) + ((alpha(2) + e)*(N+1)) - (alpha(3)*(N+1)*(N+1)) + (alpha(4)*simC_1* (N+1))
if t < 20
simV_1 = simU_1 + Emax((N+2), (t+1))
end
if simV_0 < simV_1
simchoice((i+1),t) = 1
end
end
end
end
  댓글 수: 2
Ridwan Alam
Ridwan Alam 2019년 12월 17일
the question is not very clear, sorry. which matrix is empty here?
also, what is simchoice() and what is this statement supposed to do:
simchoice((i+1),t) = 0
Sarah Schutz
Sarah Schutz 2019년 12월 17일
Hi! I'm sorry. simchoice is a matrix that I wanted to estimate the results of the simulation, but I am always getting a matrix full of zeros. It is supposed to represent the results of a simulation 1000 women about how many children they choose to have
If it helps this is the question I am trying to solve.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ridwan Alam
Ridwan Alam 2019년 12월 17일
편집: Ridwan Alam 2019년 12월 17일
Looks like your indexing is off in some places:
simchoice = zeros(1000,20)
%Looping for 1000 women
for i = 1:1000
for t = 1:20
e = normrnd(0 , sqrt(sigma_e_sq),[1000,1])
if t == 1
N = 0
else
N = sum(simchoice(i, 1:(t-1)))
end
inc = alpha(5) + alpha(6) * t
simC_0 = inc - (p_n * N)
simC_1 = inc - (p_n * (N + 1))
simU_0 = simC_0 - (0.5*alpha(1)*simC_0*simC_0) + ((alpha(2) + e)*N) - (alpha(3)*N*N) + (alpha(4)*simC_0* N)
if t < 20
simV_0 = simU_0 + Emax((N), (t+1))
end
simchoice(i,t) = 0
if N <= 7
simU_1 = simC_1 - (0.5*alpha(1)*simC_1*simC_1) + ((alpha(2) + e)*(N+1)) - (alpha(3)*(N+1)*(N+1)) + (alpha(4)*simC_1* (N+1))
if t < 20
simV_1 = simU_1 + Emax((N+1), (t+1))
end
if simV_0 < simV_1
simchoice(i,t) = 1
end
end
end
end

카테고리

Help CenterFile Exchange에서 Sudoku에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by