Format Guide: Use the format ax^n + bx + c. Example: 4x^3 + 2x^2 - 5. For single variables like x, enter 1x^1.
Result:
Step-by-Step Solution:
Understanding Integrals and the Power Rule
Integration is a core concept in calculus representing the area under a curve. For polynomials, the most common method used is the Power Rule for Integration. This calculator focuses on definite integrals using this fundamental theorem.
The Fundamental Formula
The power rule states that for any term axn:
∫ axn dx = (a / (n+1)) * xn+1 + C
How to Solve Step-by-Step
Identify the Terms: Break the function into individual parts (e.g., 3x2, 2x, and 5).
Apply the Power Rule: Increase the exponent by 1 and divide the coefficient by the new exponent.
Find the Antiderivative: Combine the integrated terms to form F(x).
Evaluate Limits: Calculate F(b) – F(a) to find the total area for a definite integral.
Practical Example
Let's calculate the integral of 2x + 3 from 0 to 2:
Integral of 2x: (2/2)x2 = x2
Integral of 3: 3x
Antiderivative: F(x) = x2 + 3x
Upper Limit (2): (2)2 + 3(2) = 4 + 6 = 10
Lower Limit (0): (0)2 + 3(0) = 0
Final Result: 10 – 0 = 10
function calculateIntegral() {
var input = document.getElementById('functionInput').value.replace(/\s+/g, ");
var a = parseFloat(document.getElementById('lowerLimit').value);
var b = parseFloat(document.getElementById('upperLimit').value);
var resultArea = document.getElementById('resultArea');
var errorArea = document.getElementById('errorArea');
var stepsContainer = document.getElementById('stepsContainer');
var finalValueDiv = document.getElementById('finalValue');
var antiderivativeText = document.getElementById('antiderivativeText');
if (!input) {
errorArea.innerHTML = "Please enter a valid polynomial function.";
errorArea.style.display = 'block';
resultArea.style.display = 'none';
return;
}
// Regex to match terms: ax^n or ax or c
// Matches: [+/-][coefficient]x^[exponent] OR [+/-][coefficient]x OR [+/-][constant]
var termRegex = /([+-]?\d*\.?\d*)x(?:\^(\d*\.?\d*))?|([+-]?\d+\.?\d*)/g;
var terms = [];
var match;
while ((match = termRegex.exec(input)) !== null) {
if (match[3] !== undefined) {
// Constant term
terms.push({ coeff: parseFloat(match[3]), exp: 0 });
} else {
// Variable term
var c = match[1];
if (c === "" || c === "+") c = 1;
if (c === "-") c = -1;
var e = match[2] !== undefined ? match[2] : 1;
terms.push({ coeff: parseFloat(c), exp: parseFloat(e) });
}
}
if (terms.length === 0) {
errorArea.innerHTML = "Could not parse function. Please use the format: 3x^2 + 2x + 5";
errorArea.style.display = 'block';
resultArea.style.display = 'none';
return;
}
errorArea.style.display = 'none';
resultArea.style.display = 'block';
var stepsHtml = "Step 1: Parse the individual terms";
var integratedTerms = [];
var antiderivativeStr = "F(x) = ";
for (var i = 0; i < terms.length; i++) {
var term = terms[i];
var newExp = term.exp + 1;
var newCoeff = term.coeff / newExp;
integratedTerms.push({ coeff: newCoeff, exp: newExp });
stepsHtml += "• Term " + (i + 1) + ": " + term.coeff + "x" + term.exp + " → (" + term.coeff + "/" + newExp + ")x" + newExp + " = " + newCoeff.toFixed(3).replace(/\.?0+$/, ") + "x" + newExp + "";
var sign = (newCoeff >= 0 && i > 0) ? " + " : (newCoeff < 0) ? " – " : "";
antiderivativeStr += sign + Math.abs(newCoeff.toFixed(3).replace(/\.?0+$/, '')) + "x" + newExp + "";
}
antiderivativeText.innerHTML = "Antiderivative " + antiderivativeStr + " + C";
// Evaluation Logic
function evaluate(xValue) {
var total = 0;
for (var j = 0; j < integratedTerms.length; j++) {
total += integratedTerms[j].coeff * Math.pow(xValue, integratedTerms[j].exp);
}
return total;
}
var valB = evaluate(b);
var valA = evaluate(a);
var finalResult = valB – valA;
stepsHtml += "Step 2: Evaluate the Antiderivative at limits";
stepsHtml += "F(" + b + ") = " + valB.toFixed(4).replace(/\.?0+$/, ") + "";
stepsHtml += "F(" + a + ") = " + valA.toFixed(4).replace(/\.?0+$/, ") + "";
stepsHtml += "Step 3: Apply Fundamental Theorem of Calculus";
stepsHtml += "∫ f(x)dx = F(b) – F(a)";
stepsHtml += "Result = " + valB.toFixed(4).replace(/\.?0+$/, ") + " – " + valA.toFixed(4).replace(/\.?0+$/, ") + " = " + finalResult.toFixed(4).replace(/\.?0+$/, ") + "";
finalValueDiv.innerHTML = "Value: " + finalResult.toFixed(4).replace(/\.?0+$/, ");
stepsContainer.innerHTML = stepsHtml;
}