function pf=getpf(cf) % getpf(cf) Generates a pdf or pmf from a cumulative function. % % The algoryth used by this function sometimes display oscillatory % behavior - basically, this function is not %100 reliable. If the % probability function getpf spits out looks like a failure, you can us % the smooth function to try and salvage it. if iscf(cf)==0 error('invalid cumulative function') end x=xvals(cf); p=pvals(cf); newp=zeros(length(p), 1); if isdiscrt(cf)==1 P=0; for i=1:(length(x)), newp(i)=p(i)-P; P=p(i); end else P=(p(2)-p(1))/(x(2)-x(1)); newp(1)=P; for i=2:length(x), dx=x(i)-x(i-1); P=2*(p(i)-p(i-1))/dx-P; if P<0 P=0; end newp(i)=P; end end pf=[cf(1,1) 1; x' newp]; if ispf(pf)==0 newp=newp./ttlprob(pf); pf=[cf(1,1) 1; x' newp]; end