Borrar filtros
Borrar filtros

How to calculate random number between Inf and 10 ?

1 visualización (últimos 30 días)
Raj Arora
Raj Arora el 18 de Oct. de 2020
Comentada: Raj Arora el 18 de Oct. de 2020
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

Respuestas (1)

Ameer Hamza
Ameer Hamza el 18 de Oct. de 2020
Editada: Ameer Hamza el 18 de Oct. de 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);
  3 comentarios
Ameer Hamza
Ameer Hamza el 18 de Oct. de 2020
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 el 18 de Oct. de 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}%%
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

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by