% COMPARELDC  Comparison of exact and approximate load duration curves.
%    COMPARELDC(MU,SIGMA,LDCVEC,SEG) plots load duration curves in a Matlab
%    figure. MU and SIGMA are the mean and standard deviation of the
%    exact load duration curve. The elements of LDCVEC hold the value of
%    the approximate load duration curve for each segment. The segment
%    length is SEG. 
%
%    Example:
%	
%	mu = 100; sigma = 25;
%       ldcvec = [1 1 1 .9 .7 .3 .1 0];
%       seg = 20;
%       compareldc(mu,sigma,ldcvec,seg)
%

function compareldc(muD,sigmaD,Fvec,Pseg)

exactseg = (muD + 3*sigmaD)/1000;
currseg = 1;
d = currseg*exactseg;
durcurveval = 1 - Phi((d-muD)/sigmaD); 
while durcurveval > 1e-4
  F0ex(1,currseg) = durcurveval;
  currseg = currseg + 1;
  d = currseg*exactseg;
  durcurveval = 1 - Phi((d-muD)/sigmaD); 
end
F0ex(1,currseg) = 0;
figure(1),clf,hold on
prevval = 1;
for currseg = 1:length(F0ex)
  plot([currseg-1 currseg-1 currseg]*exactseg,...
       [prevval F0ex(currseg) F0ex(currseg)]);
  prevval = F0ex(currseg);
end
prevval = 1;
for seg = 1:length(Fvec)
  plot([(seg-1)*Pseg (seg-1)*Pseg seg*Pseg],[prevval Fvec(seg) Fvec(seg)]);
  prevval = Fvec(seg);
end