I am generating a random value from a beta probability distribution. Based on where that value sits in terms of standard deviations I want to select a random value from a lognormal distribution that also sits in that same standard deviation range.
The beta distribution value generates no problem, but the lognormal value only generates a value rarely (maybe once or twice in the 300 iterations). Not exactly sure why this is happening, which is likely a result of my very rudimentary understanding of MATLAB and coding in general. Help would be much appreciated!
Basically I've created a series of if and and statements that check where the random beta distribution value sits, and if it is within a certain standard deviation range then the code checks if the random lognormal value is in within that same range. If they are within the same range the code ends, if not the code repeats. But I am getting 0 for most if not all the lognormal values in my final array.
close all;
clc;
d= xlsread('Poro perm data for Clarke Lake.xlsx');
pdPor = d(:,2);
pdPerm = d(:,5);
meanPor = mean(pdPor);
stdPor = std(pdPor);
meanPerm = mean(pdPerm);
stdPerm = std(pdPerm);
porosity_permeability = zeros(300,2); % openspace for array
temp=[];
%Perm = [1:300,1];
Perm = zeros(1,300);
for i=1:300
porRandom = betarnd(3.1800,44.87,[1 1]);
por(i) = porRandom;
mu=1.0130;
sigma = 2.574;
permRandom =lognrnd(mu,sigma);
if porRandom <=( meanPor + stdPor) && porRandom >= (meanPor - stdPor)
if permRandom <= (meanPerm + stdPerm) && permRandom >= (meanPerm - stdPerm)
Perm(i) = permRandom;
end
elseif porRandom < (meanPor - stdPor) && porRandom > (meanPor - stdPor*2)
if permRandom < (meanPerm - stdPerm) && permRandom > (meanPerm - stdPerm*2)
Perm(i) = permRandom;
end
elseif porRandom < (meanPor - stdPor*2)
if permRandom < (meanPerm - stdPerm*2)
Perm(i) = permRandom;
end
elseif porRandom > (meanPor + stdPor) && porRandom < (meanPor + stdpdPor*2)
if permRandom > (meanPerm + stdPerm) && permRandom < (meanPerm + stdPerm*2)
Perm(i) = permRandom;
end
else porRandom > (meanPor + stdPor*2)
if permRandom > (meanPerm + stdPerm*2)
Perm(i) = permRandom;
end
end
end
% CONCATENATED ARRAYS
porosity_permeability=cat(1,por,Perm);
As described before, I want my final result to be a 2x300 matrix with the beta values in the first row and the lognormal values in the second row. The beta values generate perfectly fine, but the lognormal values are, for the most part, 0, with only a few runs producing the correct values.
Aucun commentaire:
Enregistrer un commentaire