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.
1. Designer Overview
• Set **Screen1** title to "Polynomial Solver". • Align everything to **Center**. • Use a dark background theme.
2. Coefficient Inputs
• We need A, B, and C for Ax² + Bx + C = 0. • Drag 3 **HorizontalArrangements**. • Inside each, put a **Label** (A, B, or C) and a **TextBox**. • Rename TextBoxes to 'InputA', 'InputB', 'InputC'. • Set all to **NumbersOnly**.
3. Action Button
• Drag a **Button**. • Rename it to 'FindRootsBtn'. • Set Text to "CALCULATE ROOTS". • Change **BackgroundColor** to Orange.
4. Result Display
• Drag two **Labels**. • Rename to 'Root1Lbl' and 'Root2Lbl'. • These will show our two answers separately.
🧩Part B — Blocks View (Logic & Calculation)
Switch to Blocks view. Now add the logic that makes your app actually work.
1. Switch to Blocks
• Go to the top right of your screen and click the **Blocks** button. • This takes you from the Designer to the Logic area.
2. Calculating the Discriminant (D)
• Formula: D = B² - 4AC. • Click **FindRootsBtn**. Drag the gold 'when FindRootsBtn.Click' block. • Go to the **Variables** drawer (Orange). Drag 'initialize global D to' and snap a '0' block (Blue Math) to it. • Inside the button block, use 'set global D' and create the math: (B * B) - (4 * A * C). • Use the Blue **Math** '-' and '*' blocks.
3. The 'If' Decision
• If D is negative, we have imaginary roots. • Go to the **Control** drawer (Dark Orange). Drag 'if...then...else' and snap it inside your button logic. • In the 'if' slot, check if [get global D] < 0 using a Math comparison block.
4. Displaying the Result
• If True, 'set Root1Lbl.Text to "Roots are Imaginary"'. • If False (Else), calculate x = (-B + sqrt(D)) / 2A. • Use the 'sqrt' block from the **Math** drawer (Blue). • [set Root1Lbl.Text to] [ ( -InputB.Text + sqrt(D) ) / (2 * InputA.Text) ].
🧪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)