Team 2

Linear Equation Solver

Build an app that solves systems of 2 and 3 variable linear equations using Cramer's Rule. Users enter the coefficients and constants, and the app calculates the values of each unknown variable.

🎯 Learning Goals

  • β–Ή Understand Linear Systems and intersections
  • β–Ή Apply Cramer's Rule for algebraic solving
  • β–Ή Learn determinant usage in solving and checks
  • β–Ή Build conditional logic and error handling in apps

🌎 Why This Matters

Solving equations is how we find 'equilibrium' in economics, optimize flight paths in aviation, and balance chemical equations. This app automates a process that is essential for every scientific field.

πŸ“–Understanding Systems of Linear Equations

Theory Masterclass
"

A system of linear equations is a set of equations where each equation is a straight line (in 2D) or a plane (in 3D). The solution is the point where they intersect. For 2 variables: a₁x + b₁y = c₁ aβ‚‚x + bβ‚‚y = cβ‚‚ For 3 variables: a₁x + b₁y + c₁z = d₁ aβ‚‚x + bβ‚‚y + cβ‚‚z = dβ‚‚ a₃x + b₃y + c₃z = d₃ Cramer's Rule uses determinants to find the solution: 1. Calculate D (determinant of coefficient matrix) 2. Calculate Dx (replace x-column with constants) 3. Calculate Dy (replace y-column with constants) 4. x = Dx/D, y = Dy/D If D = 0, the system has no unique solution (either no solution or infinite solutions).

Mathematical Foundation

fxD = a₁bβ‚‚ - aβ‚‚b₁ (for 2Γ—2)
fxDx = c₁bβ‚‚ - cβ‚‚b₁
fxDy = a₁cβ‚‚ - aβ‚‚c₁
fxx = Dx / D, y = Dy / D
fxIf D = 0 β†’ No unique solution

🎨Part A β€” Designer View (UI Design)

Open MIT App Inventor β†’ Switch to Designer view. Follow each step below to build the interface.

1

Set up the screen

Set Screen1 title to "Linear Equation Solver". Set BackgroundColor to dark theme. Add a Label at the top: "Enter Coefficients" with large font.

2

Add mode toggle buttons

Add a HorizontalArrangement with 2 Buttons: "2-Variable" and "3-Variable". These switch between 2-eq and 3-eq input modes.

3

Create input for 2-variable system

Add a VerticalArrangement named "TwoVarPanel". Add 2 HorizontalArrangements (one per equation). Row 1: TextBox (a₁), Label "x +", TextBox (b₁), Label "y =", TextBox (c₁) Row 2: TextBox (aβ‚‚), Label "x +", TextBox (bβ‚‚), Label "y =", TextBox (cβ‚‚) Set all TextBoxes: NumbersOnly = true, Width = 15%.

4

Create input for 3-variable system

Add a VerticalArrangement named "ThreeVarPanel" (set Visible = false initially). Add 3 rows with TextBoxes for a, b, c coefficients and d constant each. Label each row: "Equation 1", "Equation 2", "Equation 3".

5

Add Solve and Clear buttons

Add a HorizontalArrangement with: Button "SOLVE" (green background, bold) Button "CLEAR" (red background)

6

Create result display area

Add Labels: "Solution:" as a header label. ResultLabel for showing x = ..., y = ..., z = ... StatusLabel for showing "Unique Solution", "No Solution", or "Infinite Solutions".

🧩Part B β€” Blocks View (Logic & Calculation)

Switch to Blocks view. Now add the logic that makes your app actually work.

1

Mode toggle logic

When TwoVarButton.Click: Set TwoVarPanel.Visible = true Set ThreeVarPanel.Visible = false When ThreeVarButton.Click: Set TwoVarPanel.Visible = false Set ThreeVarPanel.Visible = true

2

Calculate determinant D for 2 variables

When SolveButton.Click: First, read all values: set a1 = number(TextBoxA1.Text) set b1 = number(TextBoxB1.Text) set c1 = number(TextBoxC1.Text) (constant) set a2 = number(TextBoxA2.Text) set b2 = number(TextBoxB2.Text) set c2 = number(TextBoxC2.Text) Calculate D = (a1 Γ— b2) - (a2 Γ— b1)

3

Check if solution exists

if D = 0 then: Set StatusLabel.Text = "No unique solution exists!" Set StatusLabel.TextColor = red Stop here (don't calculate further). else: Continue to next step.

4

Calculate Dx and Dy

Dx = (c1 Γ— b2) - (c2 Γ— b1) Dy = (a1 Γ— c2) - (a2 Γ— c1)

5

Find x and y values

x = Dx / D y = Dy / D Set ResultLabel.Text to: join "x = " x "\ny = " y Set StatusLabel.Text = "βœ“ Unique Solution Found" Set StatusLabel.TextColor = green

6

Build 3-variable solver (advanced)

For 3 variables, calculate the 3Γ—3 determinant: D = a1(b2c3 - b3c2) - b1(a2c3 - a3c2) + c1(a2b3 - a3b2) Then Dx, Dy, Dz by replacing each column with the constants. x = Dx/D, y = Dy/D, z = Dz/D

7

Clear button logic

When ClearButton.Click: Set all TextBox.Text = "" Set ResultLabel.Text = "" Set StatusLabel.Text = ""

8

Input validation

Before solving, check each TextBox: if any TextBox is empty β†’ show Notifier alert "Please fill all coefficients" This prevents crashes from empty or non-numeric input.

πŸ§ͺTesting Your App

  • βœ“Test: 2x + 3y = 8, x + y = 3 β†’ Expected: x=1, y=2
  • βœ“Test: x + y = 5, 2x + 2y = 10 β†’ D=0, infinite solutions
  • βœ“Test: x + y = 5, x + y = 3 β†’ D=0, no solution
  • βœ“Test with negative coefficients: -3x + 2y = 1
  • βœ“Test the 3-variable mode with known solutions

πŸš€Bonus Challenges

Extra credit β€” impress your instructor

  • β˜…Show the step-by-step calculation process, not just the answer
  • β˜…Add a graphical representation showing the two lines intersecting
  • β˜…Support decimal coefficients (not just integers)
  • β˜…Add Gauss-Jordan elimination as an alternative method