Calculus Calculator – Derivative and Integral Solver
.calculus-tool {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 25px;
border: 1px solid #e1e1e1;
border-radius: 12px;
background-color: #f9f9fb;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
.calculus-tool h2 {
color: #2c3e50;
text-align: center;
margin-top: 0;
}
.calc-section {
background: #ffffff;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
border: 1px solid #eee;
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: 600;
color: #444;
}
.input-group input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 16px;
}
.btn-container {
display: flex;
gap: 10px;
margin-top: 20px;
}
.calc-btn {
flex: 1;
padding: 12px;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: bold;
font-size: 15px;
transition: background 0.3s;
}
.btn-derivative { background-color: #3498db; color: white; }
.btn-derivative:hover { background-color: #2980b9; }
.btn-integral { background-color: #27ae60; color: white; }
.btn-integral:hover { background-color: #219150; }
.result-box {
margin-top: 20px;
padding: 15px;
background-color: #edf2f7;
border-left: 5px solid #2c3e50;
border-radius: 4px;
min-height: 40px;
}
.formula-display {
font-family: "Courier New", Courier, monospace;
font-size: 1.2em;
color: #d35400;
font-weight: bold;
}
.article-content {
line-height: 1.6;
color: #333;
margin-top: 40px;
}
.article-content h3 { color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 5px; }
.example-box {
background: #f0f7ff;
padding: 15px;
border-radius: 6px;
border-left: 4px solid #3498db;
margin: 15px 0;
}
table { width: 100%; border-collapse: collapse; margin: 20px 0; }
table th, table td { border: 1px solid #ddd; padding: 12px; text-align: left; }
table th { background-color: #f2f2f2; }
function calculateDerivative() {
var a = parseFloat(document.getElementById('coeff').value);
var n = parseFloat(document.getElementById('exponent').value);
var resultDiv = document.getElementById('calcResult');
if (isNaN(a) || isNaN(n)) {
resultDiv.innerHTML = "
Please enter valid numbers for the coefficient and exponent.";
return;
}
var newCoeff = a * n;
var newExp = n – 1;
var output = "
Derivative Result:";
output += "Function: f(x) = " + a + "x
" + n + "";
if (n === 0) {
output += "Derivative: f'(x) = 0";
} else if (newExp === 0) {
output += "Derivative: f'(x) = " + newCoeff;
} else if (newExp === 1) {
output += "Derivative: f'(x) = " + newCoeff + "x";
} else {
output += "Derivative: f'(x) = " + newCoeff + "x
" + newExp + "";
}
resultDiv.innerHTML = "
" + output + "
";
}
function calculateIntegral() {
var a = parseFloat(document.getElementById('coeff').value);
var n = parseFloat(document.getElementById('exponent').value);
var lower = parseFloat(document.getElementById('lowerLimit').value);
var upper = parseFloat(document.getElementById('upperLimit').value);
var resultDiv = document.getElementById('calcResult');
if (isNaN(a) || isNaN(n)) {
resultDiv.innerHTML = "
Please enter valid numbers for the coefficient and exponent.";
return;
}
if (n === -1) {
var indef = a + " ln|x| + C";
var output = "
Indefinite Integral:∫ " + a + "x
-1 dx =
" + indef + "";
if (!isNaN(lower) && !isNaN(upper)) {
if (lower <= 0 || upper <= 0) {
output += "
Note: For ln|x|, limits must be positive to calculate a real definite integral.";
} else {
var defVal = a * (Math.log(Math.abs(upper)) – Math.log(Math.abs(lower)));
output += "
Definite Integral [" + lower + ", " + upper + "]:";
output += "
" + defVal.toFixed(4) + "";
}
}
resultDiv.innerHTML = output;
return;
}
var newCoeff = a / (n + 1);
var newExp = n + 1;
var output = "
Indefinite Integral:";
output += "∫ " + a + "x
" + n + " dx =
" + newCoeff.toFixed(4) + "x" + newExp + " + C";
if (!isNaN(lower) && !isNaN(upper)) {
var valUpper = (a / (n + 1)) * Math.pow(upper, n + 1);
var valLower = (a / (n + 1)) * Math.pow(lower, n + 1);
var defResult = valUpper – valLower;
output += "
Definite Integral Result:";
output += "Interval: [" + lower + ", " + upper + "]";
output += "Value:
" + defResult.toFixed(4) + "";
}
resultDiv.innerHTML = output;
}