import React, { useState } from "react"; const RadicalSolutionWidget: React.FC = () => { // Equation: sqrt(x) = x - k const [k, setK] = useState(2); // Intersection logic // x = (x-k)^2 => x = x^2 - 2kx + k^2 => x^2 - (2k+1)x + k^2 = 0 // Roots via quadratic formula const a = 1; const b = -(2 * k + 1); const c = k * k; const disc = b * b - 4 * a * c; let solutions: number[] = []; if (disc >= 0) { const x1 = (-b + Math.sqrt(disc)) / (2 * a); const x2 = (-b - Math.sqrt(disc)) / (2 * a); solutions = [x1, x2].filter((val) => val >= 0); // Domain x>=0 } // Check validity against original equation sqrt(x) = x - k const validSolutions = solutions.filter( (x) => Math.abs(Math.sqrt(x) - (x - k)) < 0.01, ); const extraneousSolutions = solutions.filter( (x) => Math.abs(Math.sqrt(x) - (x - k)) >= 0.01, ); // Vis const height = 300; const range = 10; const scale = 25; const toPx = (v: number, isY = false) => isY ? height - v * scale - 20 : v * scale + 20; const pathSqrt = () => { let d = ""; for (let x = 0; x <= range; x += 0.1) { d += d ? ` L ${toPx(x)} ${toPx(Math.sqrt(x), true)}` : `M ${toPx(x)} ${toPx(Math.sqrt(x), true)}`; } return d; }; const pathLine = () => { // y = x - k const x1 = 0; const y1 = -k; const x2 = range; const y2 = range - k; return `M ${toPx(x1)} ${toPx(y1, true)} L ${toPx(x2)} ${toPx(y2, true)}`; }; // Phantom parabola path (x = y^2) - representing the squared equation // This includes y = -sqrt(x) const pathPhantom = () => { let d = ""; for (let x = 0; x <= range; x += 0.1) { d += d ? ` L ${toPx(x)} ${toPx(-Math.sqrt(x), true)}` : `M ${toPx(x)} ${toPx(-Math.sqrt(x), true)}`; } return d; }; return (
The extraneous{" "} solution is a real intersection for the squared equation (the phantom curve), but not for the original radical.