I have two probability distributions, a beta distribution and a lognormal distribution. What I want to do is draw a random value from within my beta distribution and based on where that value is in terms of a standard deviation range, then I also want to draw a random value from my lognormal distribution that also is within that standard deviation range.
For example: I draw a 0.2 from my beta distribution, which is above one standard deviation but below two standard deviations greater than the mean. Then I want to generate a random value from my lognormal distribution that is constrained between the range of my first standard deviation and second standard deviation (lets say, a value between 100 and 1000).
The standard deviation ranges are as follows: within one standard deviation, greater than one standard deviation but less than two standard deviations above the mean, greater than two standard deviations above the mean, less than one standard deviation but greater than two standard deviations below the mean, and less than two standard deviations below the mean.
What I've attempted with my code in MATLAB:
1) For each iteration, generate a random beta distribution value and a random lognormal distribution value. 2) If the beta value is within the specified standard deviation range and the lognormal value is also within that specified standard deviation range, then end the loop and print the values in an array
The issue that I am encountering is that the random beta value is generated perfectly fine, but for each lognormal value, I am left with the value as to which iteration the code has went through.
the array looks like:
0.1 1
0.12 2
0.05 3
0.07 4
.......
Here is my code:
close all;
clc;
d= xlsread('Poro perm data for Clarke Lake.xlsx');
pdPor = d(:,2);
pdPerm = d(:,8);
porosity_permeability = []; % openspace for array
temp=[];
Perm = [1:300,1];
for i=1:300
porRandom = betarnd(3.1800,44.87,[1 1]);
mu=1.0130;
sigma = 2.574;
permRandom =lognrnd(mu,sigma);
if porRandom <=(mean(pdPor) + std(pdPor)) && porRandom >= (mean(pdPor) - std(pdPor))
if permRandom <=(mean(pdPerm) + std(pdPerm)) && permRandom >= (mean(pdPer) - std(pdPer))
Perm(i) = permRandom;
end
elseif porRandom < (mean(pdPor) - (std(pdPor))) && porRandom > (mean(pdPor) - ((std(pdPor))*2))
if permRandom < (mean(pdPerm) - (std(pdPerm))) && permRandom > (mean(pdPerm) - ((std(pdPerm))*2))
Perm(i) = permRandom;
end
elseif porRandom < (mean(pdPor) - (((std(pdPor))*2)))
if permRandom < (mean(pdPerm) - (((std(pdPerm))*2)))
Perm(i) = PermRandom;
end
elseif porRandom > (mean(pdPor) + (std(pdPor))) && porRandom < (mean(pdPor) + ((std(pdPor))*2))
if permRandom > (mean(pdPerm) + (std(pdPerm))) && permRandom < (mean(pdPerm) + ((std(pdPerm))*2))
Perm(i) = permRandom;
end
else porRandom > ((mean(pdPor)) + (((std(pdPor))*2)))
if permRandom > ((mean(pdPerm)) + (((std(pdPerm))*2)))
Perm(i) = permRandom;
end
end
temp=[porRandom, Perm(i)]; % temporary space
porosity_permeability=[porosity_permeability;temp];
end
Thank you for looking into my problem! I apologize if my explanation and terminology is lackluster. I am just learning coding and MATLAB.