%!demo
%! ## Plot the PDF of a Log-logistic distribution, with parameters mu = 0
%! ## and sigma = 1, truncated at [0.5, 5] intervals. Generate 10000 random
%! ## samples from this truncated distribution and superimpose a histogram scaled
%! ## accordingly
%!
%! rand ("seed", 21);
%! data_all = loglrnd (0, 1, 30000, 1);
%! data = data_all(data_all >= 0.5 & data_all <= 5);
%! data = data(1:10000);
%!
%! pd = fitdist (data, "Loglogistic");
%! t = truncate (pd, 0.5, 5);
%!
%! [counts, centers] = hist (data, 50);
%! bin_width = centers(2) - centers(1);
%! bar (centers, counts / (sum (counts) * bin_width), 1);
%! hold on;
%! 
%! x = linspace (0.5, 5, 500);
%! y = pdf (t, x);
%! plot (x, y, "r", "linewidth", 2);
%! title ("Log-logistic distribution (mu = 0, sigma = 1) truncated at [0.5, 5]")
%! legend ("Truncated PDF", "Histogram")
%! hold off;
%!
%! ## This demonstrates truncating a Log-logistic distribution to a specific
%! ## range and visualizing the resulting distribution with random samples,
%! ## useful for bounded positive data.
