afsdf dfsaf
afsdf dfsaf

Reputation: 123

Use polyroot() or looking for other ways to compute the P[real roots]

Suppose that A,B, and C are independent random variables, each being uniformly distributed over (0,1). What is the probability that AX^2+BX+C has real roots?

I found that the probability is .2544.

How to verify that the answer you have is correct by using R? Will the command polyroot() in R be useful in determining this?

Will you have to write a program to compute the P[real roots]? I am told "Using polyroot() will require 40 times as much CPU time than a more direct method suggested by your analytical solution to this problem, which is (5+6log(2))/36).

Moreover, unless you are adroit with floating point arithmetic, you will obtain a (subtly) incorrect result. Note that no amount of such computation in R can actually "verify" such a mathematical result; it can only corroborate it--that is, you hope the code output and the math will not contradict one another. "

If that is the case, is there more efficient to achieve this result?

Upvotes: 1

Views: 718

Answers (1)

Randy Lai
Randy Lai

Reputation: 3184

Actually, you don't need polyroot, just check the discriminant.

mean(replicate(100000, {
    coef = runif(3)  
    delta = coef[2]^2 - 4*coef[1]*coef[3] # b^2 - 4ac
    delta>0
}))

if you insist to use polyroot

mean(replicate(100000, {
    coef = runif(3)  
    roots = polyroot(coef)
    all.equal(Im(roots),c(0,0))==TRUE
}))

The first method took 0.688s and the second one took 9.923s on my computer

Upvotes: 4

Related Questions