File size: 15,901 Bytes
c3d0a7a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculadora de Equação do 2º Grau</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.math-display {
font-family: 'Times New Roman', Times, serif;
font-style: italic;
}
.solution-step {
transition: all 0.3s ease;
}
.solution-step:hover {
transform: translateX(5px);
background-color: rgba(243, 244, 246, 0.5);
}
.input-highlight {
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}
</style>
</head>
<body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<div class="text-center mb-8">
<h1 class="text-4xl font-bold text-indigo-800 mb-2">Calculadora de Equação Quadrática</h1>
<p class="text-lg text-gray-600">Resolva equações do segundo grau no formato ax² + bx + c = 0</p>
</div>
<div class="bg-white rounded-xl shadow-lg overflow-hidden mb-8">
<div class="p-6">
<div class="flex flex-col md:flex-row gap-6">
<div class="flex-1">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Insira os coeficientes</h2>
<div class="space-y-4">
<div>
<label for="a" class="block text-sm font-medium text-gray-700 mb-1">Coeficiente a (x²)</label>
<div class="relative">
<input type="number" id="a" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 input-highlight" placeholder="Ex: 1" step="any">
<div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-gray-400">
<span class="math-display">x² +</span>
</div>
</div>
</div>
<div>
<label for="b" class="block text-sm font-medium text-gray-700 mb-1">Coeficiente b (x)</label>
<div class="relative">
<input type="number" id="b" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 input-highlight" placeholder="Ex: 5" step="any">
<div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-gray-400">
<span class="math-display">x +</span>
</div>
</div>
</div>
<div>
<label for="c" class="block text-sm font-medium text-gray-700 mb-1">Coeficiente c</label>
<div class="relative">
<input type="number" id="c" class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500 input-highlight" placeholder="Ex: 6" step="any">
<div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-gray-400">
<span class="math-display">= 0</span>
</div>
</div>
</div>
</div>
<div class="mt-6">
<button onclick="solveEquation()" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-medium py-3 px-4 rounded-lg transition duration-300 flex items-center justify-center gap-2">
<i class="fas fa-calculator"></i>
Calcular Raízes
</button>
</div>
</div>
<div class="flex-1">
<h2 class="text-2xl font-semibold text-gray-800 mb-4">Sua equação</h2>
<div class="bg-gray-50 p-4 rounded-lg h-32 flex items-center justify-center">
<p id="equation-display" class="text-2xl math-display text-center text-gray-700">
<span class="text-gray-400">ax² + bx + c = 0</span>
</p>
</div>
<div class="mt-4">
<div class="flex items-center gap-2 text-sm text-gray-600">
<i class="fas fa-info-circle text-indigo-500"></i>
<span>Insira os coeficientes para ver a equação formatada</span>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="solution-container" class="bg-white rounded-xl shadow-lg overflow-hidden hidden">
<div class="p-6">
<h2 class="text-2xl font-semibold text-gray-800 mb-4 flex items-center gap-2">
<i class="fas fa-brain text-indigo-600"></i>
Passo a Passo da Solução
</h2>
<div id="solution-steps" class="space-y-4">
<!-- Steps will be inserted here by JavaScript -->
</div>
<div class="mt-6 pt-4 border-t border-gray-200">
<h3 class="text-xl font-medium text-gray-800 mb-2 flex items-center gap-2">
<i class="fas fa-chart-line text-green-600"></i>
Resultado Final
</h3>
<div id="final-result" class="bg-green-50 p-4 rounded-lg">
<!-- Final result will be inserted here -->
</div>
</div>
</div>
</div>
<div class="mt-8 bg-indigo-50 rounded-lg p-4 border border-indigo-100">
<h3 class="text-lg font-medium text-indigo-800 mb-2 flex items-center gap-2">
<i class="fas fa-lightbulb text-indigo-600"></i>
Sobre a Fórmula Quadrática
</h3>
<p class="text-gray-700 mb-3">
A fórmula quadrática para resolver equações do segundo grau é:
</p>
<div class="bg-white p-3 rounded-md shadow-sm text-center mb-3">
<p class="text-xl math-display font-medium">
x = [-b ± √(b² - 4ac)] / (2a)
</p>
</div>
<p class="text-gray-700">
O discriminante Δ = b² - 4ac determina a natureza das raízes:
</p>
<ul class="list-disc pl-5 mt-2 space-y-1 text-gray-700">
<li>Δ > 0: Duas raízes reais distintas</li>
<li>Δ = 0: Uma raiz real dupla</li>
<li>Δ < 0: Duas raízes complexas conjugadas</li>
</ul>
</div>
</div>
<script>
// Update equation display in real-time
document.querySelectorAll('input').forEach(input => {
input.addEventListener('input', updateEquationDisplay);
});
function updateEquationDisplay() {
const a = document.getElementById('a').value || 'a';
const b = document.getElementById('b').value || 'b';
const c = document.getElementById('c').value || 'c';
// Format the equation with proper signs
let equation = '';
// Handle a term
if (a === '1') equation += 'x²';
else if (a === '-1') equation += '-x²';
else equation += `${a}x²`;
// Handle b term
if (b[0] === '-') {
equation += ` - ${b.slice(1) === '1' ? '' : b.slice(1)}x`;
} else {
equation += ` + ${b === '1' ? '' : b}x`;
}
// Handle c term
if (c[0] === '-') {
equation += ` - ${c.slice(1)}`;
} else {
equation += ` + ${c}`;
}
equation += ' = 0';
// Special case when all are empty
if (a === 'a' && b === 'b' && c === 'c') equation = 'ax² + bx + c = 0';
document.getElementById('equation-display').innerHTML = equation;
}
function solveEquation() {
const a = parseFloat(document.getElementById('a').value);
const b = parseFloat(document.getElementById('b').value);
const c = parseFloat(document.getElementById('c').value);
// Validate inputs
if (isNaN(a) || isNaN(b) || isNaN(c)) {
alert('Por favor, insira valores válidos para todos os coeficientes.');
return;
}
if (a === 0) {
alert('O coeficiente "a" não pode ser zero em uma equação quadrática.');
return;
}
// Clear previous solution
document.getElementById('solution-steps').innerHTML = '';
document.getElementById('final-result').innerHTML = '';
// Show solution container
document.getElementById('solution-container').classList.remove('hidden');
// Calculate discriminant
const discriminant = b * b - 4 * a * c;
// Add steps to solution
addSolutionStep(`1. Identificamos os coeficientes: a = ${a}, b = ${b}, c = ${c}`);
addSolutionStep(`2. Calculamos o discriminante Δ = b² - 4ac`);
addSolutionStep(` Δ = (${b})² - 4 × ${a} × ${c} = ${b*b} - ${4*a*c} = ${discriminant}`);
if (discriminant > 0) {
addSolutionStep(`3. Como Δ > 0, a equação tem duas raízes reais distintas`);
const sqrtDiscriminant = Math.sqrt(discriminant);
addSolutionStep(`4. Calculamos a raiz quadrada do discriminante: √${discriminant} ≈ ${sqrtDiscriminant.toFixed(4)}`);
const x1 = (-b + sqrtDiscriminant) / (2 * a);
const x2 = (-b - sqrtDiscriminant) / (2 * a);
addSolutionStep(`5. Aplicamos a fórmula quadrática:`);
addSolutionStep(` x = [ -(${b}) ± ${sqrtDiscriminant.toFixed(4)} ] / (2 × ${a})`);
addSolutionStep(` x₁ = [ ${-b} + ${sqrtDiscriminant.toFixed(4)} ] / ${2*a} ≈ ${x1.toFixed(4)}`);
addSolutionStep(` x₂ = [ ${-b} - ${sqrtDiscriminant.toFixed(4)} ] / ${2*a} ≈ ${x2.toFixed(4)}`);
// Final result
document.getElementById('final-result').innerHTML = `
<p class="text-lg font-medium text-gray-800">A equação tem duas raízes reais:</p>
<div class="mt-2 grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-blue-50 p-3 rounded-lg">
<p class="text-sm text-blue-600">Primeira raiz (x₁)</p>
<p class="text-xl math-display font-bold">${x1.toFixed(4)}</p>
</div>
<div class="bg-blue-50 p-3 rounded-lg">
<p class="text-sm text-blue-600">Segunda raiz (x₂)</p>
<p class="text-xl math-display font-bold">${x2.toFixed(4)}</p>
</div>
</div>
`;
}
else if (discriminant === 0) {
addSolutionStep(`3. Como Δ = 0, a equação tem uma raiz real dupla`);
const x = -b / (2 * a);
addSolutionStep(`4. Aplicamos a fórmula quadrática simplificada:`);
addSolutionStep(` x = -b / (2a) = -(${b}) / (2 × ${a}) = ${x.toFixed(4)}`);
// Final result
document.getElementById('final-result').innerHTML = `
<p class="text-lg font-medium text-gray-800">A equação tem uma raiz real dupla:</p>
<div class="mt-2 bg-blue-50 p-4 rounded-lg">
<p class="text-xl math-display font-bold text-center">${x.toFixed(4)}</p>
</div>
`;
}
else {
addSolutionStep(`3. Como Δ < 0, a equação não tem raízes reais, mas duas raízes complexas conjugadas`);
const realPart = -b / (2 * a);
const imaginaryPart = Math.sqrt(-discriminant) / (2 * a);
addSolutionStep(`4. Calculamos as partes real e imaginária:`);
addSolutionStep(` Parte Real = -b / (2a) = -(${b}) / (2 × ${a}) = ${realPart.toFixed(4)}`);
addSolutionStep(` Parte Imaginária = √|Δ| / (2a) = √${-discriminant} / ${2*a} ≈ ${imaginaryPart.toFixed(4)}`);
// Final result
document.getElementById('final-result').innerHTML = `
<p class="text-lg font-medium text-gray-800">A equação tem duas raízes complexas conjugadas:</p>
<div class="mt-2 grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-purple-50 p-3 rounded-lg">
<p class="text-sm text-purple-600">Primeira raiz (x₁)</p>
<p class="text-xl math-display font-bold">${realPart.toFixed(4)} + ${Math.abs(imaginaryPart).toFixed(4)}i</p>
</div>
<div class="bg-purple-50 p-3 rounded-lg">
<p class="text-sm text-purple-600">Segunda raiz (x₂)</p>
<p class="text-xl math-display font-bold">${realPart.toFixed(4)} - ${Math.abs(imaginaryPart).toFixed(4)}i</p>
</div>
</div>
`;
}
}
function addSolutionStep(text) {
const stepDiv = document.createElement('div');
stepDiv.className = 'solution-step bg-gray-50 p-3 rounded-lg';
stepDiv.innerHTML = `<p class="text-gray-800">${text}</p>`;
document.getElementById('solution-steps').appendChild(stepDiv);
}
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Luiz74/equa-o-2" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |