How to calculate random number between Inf and 10 ?

조회 수: 1 (최근 30일)
Raj Arora
Raj Arora 2020년 10월 18일
댓글: Raj Arora 2020년 10월 18일
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

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 18일
편집: Ameer Hamza 2020년 10월 18일
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);
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 10월 18일
You can do something like this
A = [-Inf 52.17 54 55.82 Inf];
B = A(:);
B(isinf(B)) = sign(B(isinf(B))).*realmax;
C = rand(numel(B)-1,1).*(B(2:end)-B(1:end-1)) + B(1:end-1);
Raj Arora
Raj Arora 2020년 10월 18일
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}%%
clear;
clc;
%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%
P(i)=m
%Matrix is used to get all the values of n together%
Q(i)=n
end
for j=1:4
k=randi(j)
a=P(k)
b=Q(k)
fprintf(' \n random sample (x,y)= %d',a,b)
z=a*b-1900
g(j)=z
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by