While problem, generating random numbers

1 visualizzazione (ultimi 30 giorni)
Marta Gonzalez
Marta Gonzalez il 7 Set 2020
Commentato: Marta Gonzalez il 10 Set 2020
Write a function called one_so_small that takes no input arguments
and returns three scalars as output arguments. If it is called this way,
[a,b,c] = one_so_small, then it repeatedly gets three numbers from the
function rand until the numbers pass this test: ten times one of the numbers
is smaller than the product of the other two numbers. For example, if the
three random numbers are 0.4, 0.03, and 0.9, then ten times the second number
is 0.3 and the product of the first and third numbers is 0.36, so ten times
one of these three numbers is smaller than the product of the other two numbers.
On the other hand, if the second number were 0.038, these three numbers
would not pass the test. Here are two sample calls. Before the sample
calls are made, the random number generator is initialized by means of rng.
In this case, it is initialized with the number 12 (non-negative integer). The
purpose of this use of rng is to make it possible to compare your results with
those below.
>> rng(12)
>> [a,b,c] = one_so_small
a =
0.014575
b =
0.91875
c =
0.53374
>> [a,b,c] = one_so_small
a =
0.033421
b =
0.95695
c =
0.90071
  8 Commenti
Geoff Hayes
Geoff Hayes il 9 Set 2020
Marta - you are assigning random values to a, b, and c, but like Mohammad says you need to assign the values you a,b,c before you check the condition.
while true
a=rand;
b=rand;
c=rand;
if % your conditions - what would they be?
% exit the loop
end
end
So you keep generating your 3 random numbers until one of the three conditions is satisifed. And once satisfied, you can exit the loop? (How would you do this?)
Marta Gonzalez
Marta Gonzalez il 10 Set 2020
Ohh now I undertsand what you mean, I was wrong in my perspective of the problem. Now it really works.
Thanks both of you

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by