Clear Filters
Clear Filters

Generating a random number from a distribution then generating another number from a different truncated distribution

2 views (last 30 days)
Hello, I am just learning MATLAB (with the help of a colleague) and I am having trouble creating some code to perform what I want. To elaborate: I am generating a random number from within a beta distribution. Based on where the randomly generated number sits within the distribution (lets say, within one standard deviation of the beta dist mean), then I want to generate another number from a different, lognormal distribution that is also within one standard deviation of the lognormal dist mean. I also want to do this for when the randomly generated beta dist number falls within the 2nd and 3rd standard deviations above and below the mean and when the randomly generated beta dist number falls above and below the 3rd standard deviation.
Currently, my random beta dist number generates fine for the 300 iterations but the lognormal dist number does not (it seems to just be recording the value for how many iterations the code has went through). I believe part of the issue is that the randomly generated lognormal dist number is not attached to the truncated distribution. I am not absolutely sure how to fix this, but someone could offer some insight into where I've gone wrong that would be fantastic.
Thank you!
close all;
clc;
d= xlsread('Poro perm data for Clarke Lake.xlsx'); % excel sheet with beta and lognormal distribution data
pdPor = d(:,2); % beta distribution column
pdPerm = d(:,8); % lognormal distribution column
porosity_permeability = []; % openspace for array
temp=[];
Perm = [1:300,1];
for i=1:300
porRandom = betarnd(3.1800,44.87,[1 1]); % generate a random beta distribution value for each iteration
mu=1.0130; % lognormal dist mean
sigma = 2.574; % lognormal dist standard deviation
permRandom =lognrnd(mu,sigma); % randomly generated number from lognormal distribution with defined mu and sigma
if porRandom <=(mean(pdPor) + std(pdPor)) && porRandom >= (mean(pdPor) - std(pdPor)) % if the random beta dist number is between one std then truncate the lognormal distribution at one std below and above the mean
t = truncate(pdPerm,-1.56163,3.587676)
if permRandom <=(mean(pdPerm) + std(pdPerm)) && permRandom >= (mean(pdPer) - std(pdPer))
Perm(i) = permRandom; % generate a random number from truncated lognormal dist
end
elseif porRandom < (mean(pdPor) - (std(pdPor))) && porRandom > (mean(pdPor) - ((std(pdPor))*2)) % if random beta dist number is less than one std but greater than two std below the mean then truncate the the lognormal distibution using the same std constraints
if permRandom < (mean(pdPerm) - (std(pdPerm))) && permRandom > (mean(pdPerm) - ((std(pdPerm))*2))
t = truncate(pdPerm,-4.13628,-1.56163)
Perm(i) = permRandom; % generate a random number from truncated lognormal dist
end
elseif porRandom < (mean(pdPor) - (((std(pdPor))*2))) % if random beta dist number is less than two std below the mean then truncate the the lognormal distibution using the same std constraints
t = truncate(pdPerm,1e-8,-4.13628)
if permRandom < (mean(pdPerm) - (((std(pdPerm))*2)))
Perm(i) = PermRandom; % generate a random number from truncated lognormal dist
end
elseif porRandom > (mean(pdPor) + (std(pdPor))) && porRandom < (mean(pdPor) + ((std(pdPor))*2)) % if random beta dist number is greater than one std but less than two std above the mean then truncate the the lognormal distibution using the same std constraints
t = truncate(pdPerm,3.587676,4.574652)
if permRandom > (mean(pdPerm) + (std(pdPerm))) && permRandom < (mean(pdPerm) + ((std(pdPerm))*2))
Perm(i) = permRandom; % generate a random number from truncated lognormal dist
end
else porRandom > ((mean(pdPor)) + (((std(pdPor))*2))) % if random beta dist number is greater than two std above the mean then truncate the the lognormal distibution using the same std constraints
t = truncate(pdPerm,4.574652,inf)
if permRandom > ((mean(pdPerm)) + (((std(pdPerm))*2)))
Perm(i) = permRandom; % generate a random number from truncated lognormal dist
end
end
temp=[porRandom, Perm(i)]; % temporary space
porosity_permeability=[porosity_permeability;temp]; % array for por and perm- final matrix
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!