Enter formula for term you are testing. Use 'n' as variable.
Enter formula for the known series.
Known Convergent
Known Divergent
Does ∑bn converge or diverge?
What is the Direct Comparison Test?
The Direct Comparison Test (DCT) is a fundamental method in calculus used to determine the convergence or divergence of an infinite series. It works by comparing the series in question, ∑ an, to a "benchmark" series, ∑ bn, whose behavior (convergence or divergence) is already known.
The Logic of Comparison
For two series with positive terms, the logic follows two strict rules:
Convergence Case: If the benchmark series ∑ bnconverges, and the terms of your series are smaller (an ≤ bn) for all sufficiently large n, then ∑ an also converges. Think of this as the "ceiling" effect—if the sum of the larger terms is finite, the sum of the smaller terms must also be finite.
Divergence Case: If the benchmark series ∑ bndiverges (sums to infinity), and the terms of your series are larger (an ≥ bn) for all sufficiently large n, then ∑ an also diverges. This is the "floor" effect—if the smaller sum is infinite, the larger sum must be infinite.
Choosing a Comparison Series (bn)
The success of this test depends entirely on choosing the right bn. Common choices include:
P-Series:∑ 1/np. Converges if p > 1, diverges if p ≤ 1.
Geometric Series:∑ arn. Converges if |r| < 1.
Example Calculation
Suppose we want to test ∑ 1/(n2 + 1).
Step 1: Choose bn = 1/n2 because it dominates the behavior as n grows.
Step 2: Determine behavior of bn. Since p = 2 > 1, it is a convergent p-series.
Step 3: Compare terms. Since n2 + 1 > n2, the fraction 1/(n2 + 1) < 1/n2.
Conclusion: Since an < bn and ∑ bn converges, ∑ an converges.
function performComparison() {
// Get Inputs
var anStr = document.getElementById('an_expression').value.trim();
var bnStr = document.getElementById('bn_expression').value.trim();
var bnBehavior = document.getElementById('bn_behavior').value;
var startN = parseInt(document.getElementById('start_n').value);
var resultDiv = document.getElementById('result');
// Validation
if (!anStr || !bnStr || isNaN(startN)) {
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'Please enter valid formulas and a starting integer.';
return;
}
// Preprocess strings to handle JS Math syntax (e.g. ^ to **)
// We replace ^ with ** for powers
var safeAn = anStr.replace(/\^/g, '**');
var safeBn = bnStr.replace(/\^/g, '**');
// Allow "sin", "cos", "log", "sqrt" without "Math." prefix by replacing them
var mathFuncs = ['sin', 'cos', 'tan', 'log', 'exp', 'sqrt', 'abs', 'pow'];
for (var i = 0; i < mathFuncs.length; i++) {
var func = mathFuncs[i];
var regex = new RegExp('\\b' + func + '\\b', 'g');
safeAn = safeAn.replace(regex, 'Math.' + func);
safeBn = safeBn.replace(regex, 'Math.' + func);
}
var getAn, getBn;
try {
getAn = new Function('n', 'return ' + safeAn);
getBn = new Function('n', 'return ' + safeBn);
} catch (e) {
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'Syntax Error in formula. Please use standard math notation (e.g., 1/(n*n+1)).';
return;
}
// Logic Check
var checkLimit = 5; // Check first 5 terms starting from startN
var smallerCount = 0;
var largerCount = 0;
var tableHTML = '
n
an (Test)
bn (Known)
Relation
';
var validTerms = true;
for (var n = startN; n < startN + checkLimit; n++) {
var valA, valB;
try {
valA = getAn(n);
valB = getBn(n);
} catch (err) {
validTerms = false;
break;
}
// Check if values are valid numbers
if (!isFinite(valA) || !isFinite(valB)) {
validTerms = false;
break;
}
// Check positivity (DCT requirement)
if (valA <= 0 || valB <= 0) {
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'Error: The Direct Comparison Test requires terms to be positive. Your input produced non-positive values at n=' + n + '.';
return;
}
var relation = "";
if (valA < valB) {
relation = "an < bn";
smallerCount++;
} else if (valA > valB) {
relation = "an > bn";
largerCount++;
} else {
relation = "an = bn";
smallerCount++; // Treat equal as "smaller or equal" for convergence, "larger or equal" for divergence logic
largerCount++;
}
tableHTML += '
' + n + '
' + valA.toExponential(4) + '
' + valB.toExponential(4) + '
' + relation + '
';
}
tableHTML += '
';
if (!validTerms) {
resultDiv.style.display = 'block';
resultDiv.innerHTML = 'Error evaluating formulas. Likely division by zero or invalid domain.';
return;
}
// Determine Conclusion
var conclusionHTML = "";
var verdictClass = "";
var explanation = "";
// Logic Matrix
// 1. bn Converges AND an an Converges
// 2. bn Diverges AND an >= bn (largerCount == checkLimit) -> an Diverges
// Otherwise: Inconclusive
// Note: Using checkLimit to ensure consistency over the sampled range
var consistentSmaller = (smallerCount === checkLimit); // Allow equality
var consistentLarger = (largerCount === checkLimit); // Allow equality
if (bnBehavior === 'converges') {
if (consistentSmaller) {
conclusionHTML = "Converges";
verdictClass = "verdict-converges";
explanation = "Since ∑ bn converges and an ≤ bn for the tested values, ∑ anconverges by the Direct Comparison Test.";
} else {
conclusionHTML = "Inconclusive";
verdictClass = "verdict-inconclusive";
explanation = "The test is inconclusive. You selected that ∑ bn converges, but an is not consistently smaller than or equal to bn. The Direct Comparison Test cannot determine convergence if the test series is larger than a convergent series.";
}
} else { // bn diverges
if (consistentLarger) {
conclusionHTML = "Diverges";
verdictClass = "verdict-diverges";
explanation = "Since ∑ bn diverges and an ≥ bn for the tested values, ∑ andiverges by the Direct Comparison Test.";
} else {
conclusionHTML = "Inconclusive";
verdictClass = "verdict-inconclusive";
explanation = "The test is inconclusive. You selected that ∑ bn diverges, but an is not consistently larger than or equal to bn. The Direct Comparison Test cannot determine divergence if the test series is smaller than a divergent series.";
}
}
// Construct Final Output
var output = '