Desmos Quadratic Equation Solver
Use this calculator to find the roots (solutions) of a quadratic equation in the standard form: ax² + bx + c = 0. Simply enter the coefficients a, b, and c, and the calculator will provide the real or complex roots, along with the discriminant.
function calculateQuadraticRoots() {
var a = parseFloat(document.getElementById('coefficientA').value);
var b = parseFloat(document.getElementById('coefficientB').value);
var c = parseFloat(document.getElementById('coefficientC').value);
var resultDiv = document.getElementById('quadraticResult');
resultDiv.innerHTML = "; // Clear previous results
if (isNaN(a) || isNaN(b) || isNaN(c)) {
resultDiv.innerHTML = 'Please enter valid numbers for all coefficients.';
return;
}
if (a === 0) {
resultDiv.innerHTML = 'Coefficient \'a\' cannot be zero for a quadratic equation. This is a linear equation.';
// Optionally solve for linear equation
if (b !== 0) {
var x = -c / b;
resultDiv.innerHTML += 'For a linear equation (' + b + 'x + ' + c + ' = 0), the solution is x = ' + x.toFixed(4) + ";
} else if (c === 0) {
resultDiv.innerHTML += 'This equation (0 = 0) has infinite solutions.';
} else {
resultDiv.innerHTML += 'This equation (' + c + ' = 0) has no solution.';
}
return;
}
var discriminant = (b * b) – (4 * a * c);
var root1, root2;
resultDiv.innerHTML += '
Discriminant (b² – 4ac): ' + discriminant.toFixed(4) + ";
if (discriminant > 0) {
root1 = (-b + Math.sqrt(discriminant)) / (2 * a);
root2 = (-b – Math.sqrt(discriminant)) / (2 * a);
resultDiv.innerHTML += '
Nature of Roots: Two distinct real roots.';
resultDiv.innerHTML += '
Root 1 (x₁): ' + root1.toFixed(4) + ";
resultDiv.innerHTML += '
Root 2 (x₂): ' + root2.toFixed(4) + ";
} else if (discriminant === 0) {
root1 = -b / (2 * a);
resultDiv.innerHTML += '
Nature of Roots: One real root (repeated).';
resultDiv.innerHTML += '
Root (x): ' + root1.toFixed(4) + ";
} else { // discriminant < 0
var realPart = -b / (2 * a);
var imaginaryPart = Math.sqrt(Math.abs(discriminant)) / (2 * a);
resultDiv.innerHTML += '
Nature of Roots: Two complex conjugate roots.';
resultDiv.innerHTML += '
Root 1 (x₁): ' + realPart.toFixed(4) + ' + ' + imaginaryPart.toFixed(4) + 'i';
resultDiv.innerHTML += '
Root 2 (x₂): ' + realPart.toFixed(4) + ' – ' + imaginaryPart.toFixed(4) + 'i';
}
}
.desmos-calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 8px;
padding: 25px;
max-width: 600px;
margin: 20px auto;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
color: #333;
}
.desmos-calculator-container h2 {
color: #2c3e50;
text-align: center;
margin-bottom: 20px;
font-size: 1.8em;
}
.desmos-calculator-container p {
line-height: 1.6;
margin-bottom: 15px;
font-size: 0.95em;
}
.calculator-form .form-group {
margin-bottom: 15px;
display: flex;
align-items: center;
}
.calculator-form label {
flex: 1;
font-weight: bold;
margin-right: 15px;
color: #555;
font-size: 1em;
}
.calculator-form input[type="number"] {
flex: 2;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1em;
box-sizing: border-box;
transition: border-color 0.3s ease;
}
.calculator-form input[type="number"]:focus {
border-color: #007bff;
outline: none;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.3);
}
.calculator-form button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
margin-top: 20px;
}
.calculator-form button:hover {
background-color: #0056b3;
transform: translateY(-2px);
}
.calculator-result {
margin-top: 25px;
padding: 20px;
background-color: #e9f7ef;
border: 1px solid #d4edda;
border-radius: 8px;
color: #155724;
font-size: 1em;
}
.calculator-result p {
margin-bottom: 8px;
line-height: 1.5;
}
.calculator-result p:last-child {
margin-bottom: 0;
}
.calculator-result strong {
color: #0f3d1a;
}
.calculator-result .error {
color: #721c24;
background-color: #f8d7da;
border-color: #f5c6cb;
padding: 10px;
border-radius: 5px;
margin-bottom: 15px;
}
Understanding Quadratic Equations and Desmos
A quadratic equation is a polynomial equation of the second degree, meaning it contains at least one term in which the unknown variable is raised to the power of two. The standard form is ax² + bx + c = 0, where 'x' represents an unknown, and 'a', 'b', and 'c' are coefficients, with 'a' not equal to zero.
These equations are fundamental in various fields, from physics (e.g., projectile motion) to engineering and economics. Finding the solutions (or roots) of a quadratic equation means finding the values of 'x' that satisfy the equation. Graphically, these roots represent the x-intercepts of the parabola that the quadratic equation forms when plotted on a coordinate plane.
The Quadratic Formula
The most common method to solve quadratic equations is using the quadratic formula:
x = [-b ± sqrt(b² - 4ac)] / 2a
This formula directly provides the values of 'x' once 'a', 'b', and 'c' are known.
The Discriminant
A crucial part of the quadratic formula is the expression under the square root: b² - 4ac. This is called the discriminant, and its value tells us about the nature of the roots without actually calculating them:
- If
discriminant > 0: There are two distinct real roots. The parabola intersects the x-axis at two different points.
- If
discriminant = 0: There is exactly one real root (a repeated root). The parabola touches the x-axis at exactly one point (its vertex).
- If
discriminant < 0: There are two complex conjugate roots. The parabola does not intersect the x-axis at all.
How Desmos Helps
Desmos is an incredibly powerful and intuitive online graphing calculator that makes visualizing and understanding quadratic equations simple. You can input any quadratic equation (e.g., y = ax² + bx + c) directly into Desmos, and it will instantly graph the parabola. You can then easily identify the x-intercepts (the roots), the vertex, and observe how changing the coefficients 'a', 'b', or 'c' affects the shape and position of the graph.
For example, if you input y = x^2 - 3x + 2 into Desmos, you'll see a parabola that crosses the x-axis at x=1 and x=2, which are the roots this calculator would find for a=1, b=-3, c=2.
This calculator provides the numerical solutions, complementing Desmos's visual representation, giving you a complete understanding of quadratic equations.