function [P,pv]=creaptrid(a,c,n)
% Input: dimensione n; 0<a,c<1
% Output: P e' tridiagonale stocastica con elementi sottodiag a, sopradiag c, e diag 1-a-c + boundary conditions; pv e' il probability vector

b=1-a-c;
P=c*diag(ones(n-1,1),1)+a*diag(ones(n-1,1),-1)+b*diag(ones(n,1));
P(1,1)=P(1,1)+a;P(n,n)=P(n,n)+c;

pv=ones(n,1);
r=c/a;
for i=2:n, pv(i)=pv(i-1)*r; end; 
pv=pv/sum(pv);

