Theoretical result for probability problem to cut rod s.t. it makes triangle doesn't match the actual experiment.

168 Views Asked by At

I was solving the following probability problem yesterday:

Given a rod of length L, find the number of ways to cut the rod into thre parts s.t. these parts form a triangle.

Now, it's a standard problem and multiple solutions can be found online. Added a few links in solutions (Feel free to go and explore). Obviously, all of them arrive at the same conclusion that the required probability is 1 / 4 = 0.25.

Then, I decided to conduct an experiment and write a python script to simulate the experiment. I perform the experiment 10^7 times (takes a while to calculate the result) but always comes up with ~0.19 no matter what I choose number of experiments and length of rod to be.

I would like to find out why theoretical and practical result doesn't match?

Here is my python script:

import numpy as np

def rod_cut(L):
    x = np.random.uniform(0, L)
    y = np.random.uniform(0, L - x)
    z = L - (x + y)
    return (x, y, z)


def is_triangle(datapoint):
    a, b, c = datapoint
    return a + b >= c and \
           b + c >= a and \
           a + c >= b

def perform_experiment():
    N = 10000000
    L = 1.0
    datapoints = [rod_cut(L) for _ in range(N)]
    successes = sum([is_triangle(datapoint) for datapoint in datapoints])
    print("Probability of cutting rod s.t it makes a triangle = ", successes / N)

perform_experiment()

Note: I tried making a frequency distribution graph of the random numbers that numpy generates and it comes out to be uniform. So I trust that numpy.random.uniform is generating a uniform distribution of random numbers as expected.

Solution based on algebraic inequalities:
1. (From quora) [https://www.quora.com/A-rod-is-broken-into-three-parts-what-is-the-probability-that-the-three-parts-can-be-arranged-to-form-a-triangle]

1

There are 1 best solutions below

0
On

There are 2 cases:-

Case -I : you select 2 random points (X,Y) and then break the sticks at these two joints.

Then your r.v's: $X\sim Uni(0,l) \qquad Y\sim Uni(0,l) , \text{ are independent}$

Now you have got 3 pieces, $X,Y,L-(X+Y)$

If you remember there is a basic property of a triangle Sum of two sides should be more than the third side.

SO you need work these 3 subcases : $$ P(X+Y \ge l-(X+Y));\quad P(X+ l-(X+Y)\ge Y) ;\quad P(l-(X+Y)+Y \ge X)$$

$\Rrightarrow P(X+Y \ge l-(X+Y))= P(2X+2Y \ge l)=0.5 $

$\Rrightarrow P( P(X+ l-(X+Y)\ge Y))= P(l\ge 2Y)=\frac{1}{2} $

$\Rrightarrow P( P(Y+ l-(X+Y)\ge X))= P(l\ge 2X)=\frac{1}{2} $

and similarly i hope that you can do the rest of the problem.The answer shall be the product of the subcases.

Case-II: You select a random point X on the stick and cut out the piece of length X . Then you take another random point Y on the cut out piece of X and break it at that point.

Then your random variables are :$X\sim Uni(0,l) \quad Y|X=x \sim Uni(0,x)$

Then the the length of the pieces you get:$Y,X-Y,L-X$

Work it out in the similar way as mentioned above and you will get the results.

Hope this helps.