How to calculate random number between Inf and 10 ?

3 次查看(过去 30 天)
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 中查找有关 Particle & Nuclear Physics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by