Polynomial Root Finder
Build an app that finds the roots of linear and quadratic equations using the quadratic formula. It also handles imaginary roots and provides step-by-step discriminant analysis.
🎯 Learning Goals
- ▹ Master the Quadratic Formula and Discriminant
- ▹ Differentiate between Real and Imaginary roots
- ▹ Understand Linear vs Quadratic growth
- ▹ Implement complex math equations in blocks
🌎 Why This Matters
Polynomials describe almost everything that curves — from the path of a basketball to the shape of satellite dishes. Real-world problems often have 'hidden' quadratic relationships, and this app is the key to solving them.
📖Understanding Polynomials & Their Roots
Theory MasterclassA polynomial is an expression like ax² + bx + c. The "roots" are the values of x where the polynomial equals zero. Quadratic Equation: ax² + bx + c = 0 The roots are found using the Quadratic Formula: x = (-b ± √(b²-4ac)) / 2a The Discriminant (D = b²-4ac) tells us the nature of roots: • D > 0 → Two distinct real roots • D = 0 → Two equal real roots (one repeated root) • D < 0 → Two complex (imaginary) roots Cubic Equation: ax³ + bx² + cx + d = 0 More complex to solve. For this app, we can use Cardano's method for special cases or a numerical approach — try values from -100 to 100 to find where the polynomial changes sign. Sum of roots (quadratic): x₁ + x₂ = -b/a Product of roots (quadratic): x₁ × x₂ = c/a
Mathematical Foundation
🎨Part A — Designer View (UI Design)
Open MIT App Inventor → Switch to Designer view. Follow each step below to build the interface.
Set up the screen
Set Screen1 title to "Polynomial Root Finder". Use a professional dark theme.
Add equation type selector
Add HorizontalArrangement with 2 Buttons: "Quadratic (ax²+bx+c)" and "Cubic (ax³+bx²+cx+d)" These toggle which input panel is visible.
Create quadratic input
Add a VerticalArrangement named QuadPanel: Add HorizontalArrangement with: TextBox (a), Label "x² +", TextBox (b), Label "x +", TextBox (c), Label "= 0" Set TextBoxes: NumbersOnly = true, Hint = "0", Width = 20%
Create cubic input
Add VerticalArrangement named CubicPanel (Visible = false): TextBox for a, b, c, d with labels showing x³, x², x, constant.
Add action buttons
Add Buttons: "Find Roots" (main action, green) "Analyze Discriminant" (blue) "Sum & Product" (orange) "Clear" (red)
Create result area
Add Labels: DiscriminantLabel: Shows D value and nature Root1Label: Shows first root Root2Label: Shows second root ExtraInfoLabel: Shows sum/product of roots
🧩Part B — Blocks View (Logic & Calculation)
Switch to Blocks view. Now add the logic that makes your app actually work.
Calculate the Discriminant
When FindRootsButton.Click: 1. Read a, b, c from TextBoxes (convert to numbers) 2. Check if a = 0 (not quadratic → show error) 3. D = (b × b) - (4 × a × c) 4. Set DiscriminantLabel.Text = "Discriminant = " + D
Handle D > 0 (two real roots)
if D > 0: root1 = (-b + sqrt(D)) / (2 × a) root2 = (-b - sqrt(D)) / (2 × a) Set Root1Label.Text = "x₁ = " + root1 Set Root2Label.Text = "x₂ = " + root2 Set NatureLabel = "Two distinct real roots"
Handle D = 0 (equal roots)
if D = 0: root = -b / (2 × a) Set Root1Label.Text = "x₁ = x₂ = " + root Set Root2Label.Text = "(Double root)" Set NatureLabel = "Two equal real roots"
Handle D < 0 (complex roots)
if D < 0: realPart = -b / (2 × a) imagPart = sqrt(-D) / (2 × a) (note: sqrt of positive -D) Set Root1Label = "x₁ = " + realPart + " + " + imagPart + "i" Set Root2Label = "x₂ = " + realPart + " - " + imagPart + "i" Set NatureLabel = "Two complex conjugate roots"
Calculate Sum & Product
When SumProductButton.Click: sumRoots = -b / a productRoots = c / a Display: "Sum of roots = " + sumRoots Display: "Product of roots = " + productRoots
Cubic root finder (numerical method)
For the cubic equation, use a simple numerical search: 1. Loop x from -100 to 100 in steps of 0.1 2. Calculate f(x) = ax³ + bx² + cx + d 3. If f(x) is very close to 0 (between -0.05 and 0.05), that x is a root 4. Store found roots in a list and display them This is a beginner-friendly approach. It finds real roots only.
Input validation
Check: if a = 0 for quadratic → show "Not a quadratic equation (a cannot be 0)" Check: if any TextBox is empty → show "Please fill all coefficients"
🧪Testing Your App
- ✓x² - 5x + 6 = 0 → roots are 3 and 2 (D=1, two real roots)
- ✓x² - 4x + 4 = 0 → root is 2 (D=0, equal roots)
- ✓x² + x + 1 = 0 → complex roots (D=-3)
- ✓x² - 2 = 0 → roots are ±√2 ≈ ±1.414
- ✓Verify: sum of roots = -b/a, product = c/a
🚀Bonus Challenges
Extra credit — impress your instructor
- ★Plot the parabola on a Canvas showing where it crosses the x-axis
- ★Add a 'Generate Random Equation' button for practice
- ★Show the vertex of the parabola: (-b/2a, f(-b/2a))
- ★Add support for equations entered as text strings (parsing)