While problem, generating random numbers
Mostrar comentarios más antiguos
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 comentarios
Marta Gonzalez
el 7 de Sept. de 2020
the cyclist
el 7 de Sept. de 2020
I don't think so.
a, b, and c are the outputs. You don't initialize them; you generate them using the random number generator function rand.
Steven Lord
el 7 de Sept. de 2020
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Marta Gonzalez
el 8 de Sept. de 2020
Editada: Geoff Hayes
el 9 de Sept. de 2020
Mohammad Sami
el 8 de Sept. de 2020
While your idea with while loop is correct, you need to assign the values you a,b,c before you check the condition. Every call to rand will generate a new value.
Marta Gonzalez
el 9 de Sept. de 2020
Geoff Hayes
el 9 de Sept. de 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
el 10 de Sept. de 2020
Respuestas (0)
Categorías
Más información sobre Correlation and Convolution en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!