1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Rand function matlab

  1. Sep 6, 2015 #1
    1. The problem statement, all variables and given/known data

    The number of iterations it takes for the product of two random numbers to produce a number less than 1e-5.
    2. Relevant equations

    3. The attempt at a solution

    while z < 1e-05
    count1 = count + 1;
    x = rand(1,1); %rand 1x1 matrix
    z = floor(a + (b-a+1) * rand(b,1));
    if z < 1e-05


    Now I keep getting an error saying:
    Error using rand
    Size inputs must be scalar.

    Why is this?


    while 2
    % randomIntegers < 1e-05
    count1 = count1 +1;
    randomIntegers = randi([-10,10],[20,1]);

    if randomIntergars > 1e-05


    I tried this and it's still not working
    Last edited: Sep 6, 2015
  2. jcsd
  3. Sep 6, 2015 #2


    User Avatar
    2017 Award

    Staff: Mentor

    Why do you want to produce random integers? I guess the random numbers are supposed to be floats between 0 and 1.
    That looks like the opposite of what you want to do.
    What does that line do? What are a and b? Why floor()?

    rand(1,1) returns a 1x1-matrix of random numbers, which is just a random number. Anyway, the inputs have to be scalar, apparently your b is not a scalar - what is b?
  4. Sep 6, 2015 #3
    Essentially what I want to do is generate two random numbers and their product being less than 1e-05.

    That is all in trying to do.
  5. Sep 6, 2015 #4


    User Avatar
    2017 Award

    Staff: Mentor

    "Two random numbers" is too unspecific. Dice rolls give random integers between 1 and 6 - they are random numbers, but clearly not those you want here because their product is never smaller than 1.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: Rand function matlab
  1. MATLAB Function (Replies: 0)

  2. Signum function Matlab (Replies: 4)