function npf=smooth(pf, n) % smooth(pf, n) Attempts to smooth out a probability density function. % May be useful to salvage functions generated by getpf that don't turn % out so good. n is an optional parameter, specifying the number of % interations to be done; 1 is the default. if ispf(pf)==0 error('not a valid probability function') end if isdiscrt(pf)==1 error('smooth is only for use with continuous functions') end if nargin==1 n=1; end if n>1 pf=smooth(pf, n-1); end x=xvals(pf); p=pvals(pf); np=zeros(size(p)); np(1)=p(1); for i=2:length(p), np(i)=(p(i)+p(i-1))/2; end npf=[pf(1,:); x' np']; if ispf(npf)==0 np=np./ttlprob(npf); npf=[pf(1,:); x' np']; end