"Precise" random variables from a distribution

1 visualización (últimos 30 días)
Yuriy
Yuriy el 8 de Ag. de 2022
Comentada: Yuriy el 12 de Ag. de 2022
Dear community,
I have an interval from 0 to 1 with a step 0.01 (also can be considered as from 0 to 100). This 101 values unifromly distruted on this interval.
I am trying to randomly draw two values from this interval and expect them to look like 0.15 and 0.25 or 0.9 and 0.56, etc.
I use the following code:
b = 1;
N = 0:0.01:1;
for i = 0:0.01:1
p1 = rand;
p2 = rand;
end
This gives me two random values between 0 and 1 but they have a smaller step, for instance, it returns p1 = 0.0538 and p2 = 0.7781.
Any help will be highly appreciated!

Respuesta aceptada

Steven Lord
Steven Lord el 8 de Ag. de 2022
Since 0.01 cannot be exactly represented in double precision, your values may not be exactly multiples of one-hundredth. But if you want to draw elements from a specific set of values, you can use randperm (without replacement) or randi (with replacement) to generate indices into that set.
S = [0, 5, 42, -999];
withoutReplacement = randperm(numel(S), 3) % Ask for 3 of the elements of S
withoutReplacement = 1×3
3 2 1
withReplacement = randi(numel(S), [1 3])
withReplacement = 1×3
3 1 3
S(withoutReplacement)
ans = 1×3
42 5 0
S(withReplacement)
ans = 1×3
42 0 42
  11 comentarios
Yuriy
Yuriy el 12 de Ag. de 2022
Yes, you are right. My apologies. So, I have 2 firms, they draw prices p1 and p2. If p1 < p2, then this firm has two options for a profit:
  1. Profit_1 = (p1 + p2)*((1-a)/2 +a) or
  2. Profit_2 = (p1+b)(1-a)
Where "a" is just a parameter, any number from interval (0,1), I can set it manually. Equalising it, I can see where they cross each other, but the patterns of these curves aren't clear.
Using formula above for random value I can draw one case and plot it. But I want to plot all possible combinatitons and see a "beahviour" of this curves. This will help me to decide which of two options of profit I have to choose when I set a value for "a".
Yuriy
Yuriy el 12 de Ag. de 2022
so far I could do like this, but I am not sure it is correct.
a = 0.2;
v = 1;
p_bar = v;
p_low = 0;
p_hat = 0.3;
pd1 = makedist('Uniform','lower',p_low,'upper',p_bar);
pd2 = makedist('Uniform','lower',p_low,'upper',p_bar);
p_1 = (p_low:0.01:p_bar);
p_2 = (p_low:0.01:p_bar);
pdf1 = pdf(pd1,p_1);
cdf1 = cdf(pd1,p_1);
pdf2 = pdf(pd2,p_2);
cdf2 = cdf(pd2,p_2);
f_1 = @(p_1) p_1 * (a + 1-a/2) + p_2 * (a + 1-a/2);
y_1=f_1(p_1);
f_2 = @(p_1) p_1 * (a + 1-a/2) + p_bar*(1-a)/2;
y_2=f_2(p_1);
plot(p_1,y_1,p_2,y_2)

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by