%
%
%
start_octave_ferdavel
%
%
%
Ptrans=[0.8,0.2;0.3,0.7];
p11=Ptrans(1,1);
p21=Ptrans(2,1);
p12=Ptrans(1,2);
p22=Ptrans(2,2);
  T=10;
  sbar  = 100;                  
  delta = 0.9;                  % discount factor  

% Construct state and action spaces
  S = [(0:sbar)';(0:sbar)']';                % vector of states
  X = (0:sbar)';                % vector of actions
  n = length(S);                % number of states
  m = length(X);                % number of actions
  n1= length(X)
  price1=1;
  price2=2;

f = zeros(n,m);
  for i=1:n
     for k=1:m
     if X(k) <=S(i)
    f(i,k)=price2*X(k)-0.2*X(k)^1.5;
     else
    f(i,k)=-inf;
      end
      end
      end 


%
%
%
P=zeros(m,n1,n1);

 
 


%%
%%
for k=1:m;
  for i=k:n1
    P(k,i,i-k+1)=p11;
  end
end

for k=1:m;
  for i=k:n1
    P(k,i+n1,i-k+1)=p21;
  end
end


for k=1:m;
  for i=k:n1
    P(k,i,n1+i-k+1)=p12;
  end
end

for k=1:m;
  for i=k:n1
    P(k,i+n1,n1+i-k+1)=p22;
  end
end



T=20;
model.reward=f;
model.transprob=P;
model.horizon=T;
model.discount=0.95;

[v,x]=ddpsolve(model);
