import React, { useState } from 'react'; const LinearSolutionsWidget: React.FC = () => { // Model: ax + b = cx + d const [a, setA] = useState(2); const [b, setB] = useState(4); const [c, setC] = useState(2); const [d, setD] = useState(8); const isParallel = a === c; const isCoincident = isParallel && b === d; // Calculate solution if not parallel // ax + b = cx + d => (a-c)x = d-b => x = (d-b)/(a-c) const intersectionX = isParallel ? 0 : (d - b) / (a - c); const intersectionY = a * intersectionX + b; // Visualization range const range = 10; const scale = 20; // 1 unit = 20px const center = 150; // px const toPx = (val: number, isY = false) => { if (isY) return center - val * scale; return center + val * scale; }; const getLinePath = (slope: number, intercept: number) => { const x1 = -range; const y1 = slope * x1 + intercept; const x2 = range; const y2 = slope * x2 + intercept; return `M ${toPx(x1)} ${toPx(y1, true)} L ${toPx(x2)} ${toPx(y2, true)}`; }; return (
{a}x + {b} = {c}x + {d}
{isCoincident ? "Infinite Solutions" : isParallel ? "No Solution" : "One Solution"}
{/* Controls */}

Left Side (Line 1)

setA(Number(e.target.value))} className="w-full h-1 bg-indigo-200 rounded accent-indigo-600" />
setB(Number(e.target.value))} className="w-full h-1 bg-indigo-200 rounded accent-indigo-600" />

Right Side (Line 2)

setC(Number(e.target.value))} className="w-full h-1 bg-emerald-200 rounded accent-emerald-600" />
setD(Number(e.target.value))} className="w-full h-1 bg-emerald-200 rounded accent-emerald-600" />
{/* Graph */}
{/* Axes */} {/* Lines */} {/* Intersection Point */} {!isParallel && ( )} {/* Labels */} {!isParallel && (
Intersection: ({intersectionX.toFixed(2)}, {intersectionY.toFixed(2)})
)}
{/* Logic Explanation */}

Algebraic Check:

  • Subtract {c}x from both sides: {(a-c).toFixed(0)}x + {b} = {d}
  • {a === c ? ( <>
  • 0x (Variables cancel!)
  • Remaining statement: {b} = {d}
  • {b === d ? "TRUE (Identity) → Infinite Solutions" : "FALSE (Contradiction) → No Solution"}
  • ) : ( <>
  • Variables do NOT cancel.
  • {(a-c).toFixed(0)}x = {d - b}
  • One unique solution exists.
  • )}
); }; export default LinearSolutionsWidget;