How to calculate random number between Inf and 10 ?

7 views (last 30 days)
Suppose i have a matrix given below
A= [-Inf 52.17 54 55.82 Inf]
Now how to calculate a random number between A(1) & A(2) and the random number should be a value, not Inf
Can anyone please help me with this

Answers (1)

Ameer Hamza
Ameer Hamza on 18 Oct 2020
Edited: Ameer Hamza on 18 Oct 2020
The most negative value representable in double datatype is given by -realmax. You can do something like this
A= [-Inf 52.17 54 55.82 Inf];
x = rand();
y = x*(-realmax) + A(2);
Raj Arora
Raj Arora on 18 Oct 2020
what if i have to perform Latin hypercube sampling for the given Performance function
Can you please check this and suggest me better way for this problem
you can check the attached file for the HINTS of how to perform LHS
%%STEPS FOR LATIN HYPERCUBE SAMPLING {Performance function : G=X1*X2-1900}%%
%Dividing CDF of Lognormal distribution (38,3.8) into 4 equal intervals%
X1 = logninv(linspace(0,1,5),0.6,0.1)
%Dividing CDF of Normal distribtuion(54,2.7)into 4 equal parts
X2 = norminv(linspace(0,1,5),54,2.7)
for i=1:4
%Random value is selected for every interval for X1%
m = X1(i) + (X1(i+1)-X1(i)) .* rand(1,1)
%Random value is selected for every interval for X2%
n = X2(i) + (X2(i+1)-X2(i)) .* rand(1,1)
%Matrix is used to get all the values of m together%
%Matrix is used to get all the values of n together%
for j=1:4
fprintf(' \n random sample (x,y)= %d',a,b)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!