Hi Mark,
I understand you want to generate random samples of uncertainties in three parameters using Latin Hypercube Sampling (LHS) with specified relative uncertainties.
Your MATLAB code is correct, but it implicitly assumes a uniform distribution for the uncertainties. This is evident from how the Latin Hypercube Sampling (LHS) is scaled.
However, if we are to cover 90% of the distribution probability and we don't have a specific distribution in mind, the normal distribution is a reasonable assumption due to its common usage in uncertainty analysis.The folllowing code models the uncertainties as normally distributed:
std_dev1 = p1 * rel_unc1 / 2;
std_dev2 = p2 * rel_unc2 / 2;
std_dev3 = p3 * rel_unc3 / 2;
lhs = lhsdesign(n_samples, 3);
lhs1 = p1 + std_dev1 * norminv(lhs(:, 1), 0, 1);
lhs2 = p2 + std_dev2 * norminv(lhs(:, 2), 0, 1);
lhs3 = p3 + std_dev3 * norminv(lhs(:, 3), 0, 1);
lhs_samples = [lhs1, lhs2, lhs3];
header = {'p1', 'p2', 'p3'};
fid = fopen('p_samples.csv', 'w');
fprintf(fid, '%s,%s,%s\n', header{:});
dlmwrite('p_samples.csv', lhs_samples, '-append');
The above code has the following necessary changes to model the normal distribution:
- Standard Deviation Calculation: We calculate the standard deviation 'std_dev' for each parameter to ensure that the range covers more than 90% of the distribution, which corresponds to approximately two standard deviations for a normal distribution.
- Latin Hypercube Sampling: We generate Latin Hypercube samples for three parameters simultaneously to ensure the samples are properly correlated.
- Scaling Samples: We scale the samples using the 'norminv' function to transform the uniformly distributed Latin Hypercube samples into normally distributed samples with the specified standard deviations.
You can refer to the following references for more information on the functions used in the code above:
Hope this helps you with your work.