TASK: Estimate the probability that a "random" quadratic equation will have real roots, using a FOR loop and the RAND() function.
COMMENT: A typical quadratic equation has the form:
| \begin{align} y &= a x^2 + b x + c \end{align} |
| \begin{align} r &= \frac{-b \pm \sqrt { b^2 - 4ac } }{2a} \end{align} |
b^2 - 4ac => 0
Suppose each of the coefficients a, b, and c are choose using MATLAB's rand() function. Then sometimes, the resulting equation will have real roots and sometimes not.
Use a FOR loop to run N cases. In each case, generate a, b and c using rand(), and then test whether the equation has real roots. Let M be the number of times the equation has real roots, and report the estimated probability as M/N.
INSTRUCTIONS:
Use "input()" to get a value for N.
Initialize M.
Your FOR loop runs N times.
Set the values A, B and C by calling rand().
If the resulting equation has real roots, increase M.
End your loop
Print the value of M/N
CHECK: When you are ready to test your program, you should use a reasonably large value for N, such as 10,000 or more. It's hard to guess in advance what a good approximation to the answer will be. However, just as an example, if I run the program with just N = 20, I got an answer of 0.35. That is only a rough estimate, but now you probably know the answer should not be 0.0001 or 0.95!
SUBMIT: Your work should be stored in a script file called "hw0092.m". Your script file should begin with at least three comment lines:
% hw0092.m
% YOUR NAME
% This script (describe what it does)
% Add any comments here that you care to make.
If this problem is part of an assignment, then submit it to Canvas.