Exponential Growth/Decay (k * y)
Newton's Law of Cooling (k * (T – Ta))
Logistic Growth (r * y * (1 – y/K))
Linear Combination (x + y)
Solution Results
Step (n)
xn
yn
f(xn, yn)
What is a Differential Equation?
A differential equation is a mathematical equation that relates a function with its derivatives. In real-world applications, the functions usually represent physical quantities, while the derivatives represent their rates of change. The equation defines the relationship between the two.
This calculator specifically solves First-Order Ordinary Differential Equations (ODEs) using the Euler Method. The general form of these equations is:
dy/dx = f(x, y)
Understanding the Numerical Models
Because many differential equations cannot be solved analytically (with a simple formula), we use numerical methods to approximate the values. This tool provides three common scientific models:
Exponential Growth/Decay: Used in biology for population growth or physics for radioactive decay. dy/dx = ky.
Newton's Law of Cooling: Describes how the temperature of an object changes relative to the surrounding temperature. dT/dt = k(T – Ta).
Logistic Growth: A more realistic population model that includes a "Carrying Capacity" (K), limiting growth as resources deplete. dy/dx = ry(1 – y/K).
The Euler Method Logic
The Euler Method is the most basic numerical procedure for solving ODEs. It uses the slope at a specific point to predict the value of the function at a small distance (h) away. The formula used by this calculator is:
yn+1 = yn + h · f(xn, yn)
Where h is the step size. A smaller step size generally leads to a more accurate approximation but requires more computational steps.
Practical Example: Newton's Law of Cooling
Imagine a cup of coffee at 90°C is placed in a room that is 20°C. If the cooling constant k is -0.1, what will the temperature be after 5 minutes?
Initial x (t₀): 0
Initial y (T₀): 90
Ambient Temp (Ta): 20
Target x: 5
k: -0.1
Inputting these values into the calculator will simulate the temperature drop step-by-step, showing you the cooling curve numerically.
function solveODE() {
var eqType = document.getElementById('eqType').value;
var p1 = parseFloat(document.getElementById('param1').value);
var p2 = parseFloat(document.getElementById('param2').value);
var x0 = parseFloat(document.getElementById('x0').value);
var y0 = parseFloat(document.getElementById('y0').value);
var targetX = parseFloat(document.getElementById('targetX').value);
var h = parseFloat(document.getElementById('h').value);
if (isNaN(p1) || isNaN(p2) || isNaN(x0) || isNaN(y0) || isNaN(targetX) || isNaN(h) || h <= 0) {
alert("Please enter valid numerical values. Step size (h) must be greater than 0.");
return;
}
var tableBody = document.getElementById('tableBody');
tableBody.innerHTML = '';
var resultArea = document.getElementById('de-result-area');
resultArea.style.display = 'block';
var currentX = x0;
var currentY = y0;
var steps = 0;
var maxSteps = 1000; // Safety limit
while ((currentX < targetX) && (steps targetX && (currentX – h) < targetX) {
// This is a simple Euler implementation; for target exactness we adjust h for the final step
h = targetX – (currentX – h);
// The loop will finish on next check
}
}
// Final result row
var finalSlope = calculateSlope(eqType, currentX, currentY, p1, p2);
var rowEnd = tableBody.insertRow();
rowEnd.insertCell(0).innerHTML = steps;
rowEnd.insertCell(1).innerHTML = currentX.toFixed(4);
rowEnd.insertCell(2).innerHTML = currentY.toFixed(4);
rowEnd.insertCell(3).innerHTML = finalSlope.toFixed(4);
document.getElementById('finalResultText').innerHTML = "Estimated value of y at x = " + targetX + " is " + currentY.toFixed(6) + " (Calculated in " + steps + " steps).";
}
function calculateSlope(type, x, y, p1, p2) {
if (type === 'growth') {
return p1 * y; // dy/dx = k * y
} else if (type === 'cooling') {
return p1 * (y – p2); // dy/dx = k * (T – Ta)
} else if (type === 'logistic') {
return p1 * y * (1 – (y / p2)); // dy/dx = r * y * (1 – y/K)
} else if (type === 'linear') {
return x + y; // dy/dx = x + y
}
return 0;
}
// Dynamic Label Updates
document.getElementById('eqType').onchange = function() {
var val = this.value;
var l1 = document.getElementById('param1Label');
var l2 = document.getElementById('param2Label');
var p2Input = document.getElementById('param2');
if (val === 'growth') {
l1.innerText = "Rate Constant (k)";
l2.innerText = "N/A (Not Used)";
p2Input.disabled = true;
} else if (val === 'cooling') {
l1.innerText = "Cooling Constant (k)";
l2.innerText = "Ambient Temperature (Ta)";
p2Input.disabled = false;
} else if (val === 'logistic') {
l1.innerText = "Growth Rate (r)";
l2.innerText = "Carrying Capacity (K)";
p2Input.disabled = false;
} else {
l1.innerText = "N/A (Not Used)";
l2.innerText = "N/A (Not Used)";
p2Input.disabled = true;
}
};