New to MatLab. I am trying to graph a tree for X and keep receiving the error "Array indices must be positive integers or logical values erroArray indices must be positive integers or logical values error."
N=100;T=1;h=T/N;KAPPA = 0.1;x = zeros(N+1,N+1);ju = x;jd = x;pu = x;pd = x; % define x grid
for nIndex=1:N+1 n = nIndex-1; for jIndex=1:N+1 j = jIndex-1; x(nIndex,jIndex)=(2*j-n)*sqrt(h); endend% fill in ju and jd for each cell
for nIndex=1:N n = nIndex-1; for jIndex=1:N+1 j = jIndex-1; ju(nIndex, jIndex) = n+1; for j_star = j+1:n+1 if x(nIndex,jIndex)+mu_x(KAPPA,x(nIndex,jIndex))*h < x(nIndex + 1,j_star) ju(nIndex, jIndex) = j_star; break end end jd(nIndex, jIndex) = 0; for j_star = 1:j if x(nIndex,jIndex)+mu_x(KAPPA,x(nIndex,jIndex))*h > x(nIndex + 1,j_star) jd(nIndex, jIndex) = j_star; break end end endend% fill in pu and pd for each cell
for nIndex=1:N n = nIndex-1; for jIndex=1:N+1 j = jIndex-1; pu_numerator = mu_x(KAPPA,x(nIndex,jIndex)) - x(nIndex+1,jd(nIndex,jIndex)); pu_denominator = x(nIndex+1,ju(nIndex,jIndex)) - x(nIndex+1,jd(nIndex,jIndex)); pu_check = pu_numerator / pu_denominator; pu(nIndex,jIndex) = min(1,max(0,pu_check)); pd(nIndex,jIndex) = 1 - pu(nIndex,jIndex); endendthis is in a a defrent script function retValue=mu_x(KAPPA, x)retValue = -KAPPA*x;
Best Answer