%gambler's ruin probabilities
%for p=[0.1 0.25 9/19 0.5]
  

n=10; 
for p=[0.2:0.01:0.5]
in=[1:n];    
Pn=zeros(1,n);
if (p==1/2)
    Pn=in/n;
else 
    Pn=(1-((1-p)/p).^in)/(1-((1-p)/p)^n); 
end
 
grid on;
plot([0 in],[0 Pn], 'LineWidth',1.5, 'Color', [abs(1-2*p)^(1/3) 0 0] );
hold on;
xlabel('$i$', 'Interpreter', 'Latex')
ylabel('$P_i$', 'Interpreter', 'Latex'); 
ylim([0,1]);
xlim([0,n]);
end
title('Gambler''s ruin probabilities','FontSize',10);
hold off;
            
            