Related Rates Word Problem Calculator
.related-rates-calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 25px;
background-color: #ffffff;
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0,0,0,0.1);
color: #333;
line-height: 1.6;
}
.rr-header {
text-align: center;
margin-bottom: 30px;
border-bottom: 2px solid #f0f2f5;
padding-bottom: 20px;
}
.rr-header h2 {
color: #2c3e50;
margin-bottom: 10px;
}
.rr-row {
margin-bottom: 20px;
}
.rr-label {
display: block;
font-weight: 600;
margin-bottom: 8px;
color: #4a5568;
}
.rr-input, .rr-select {
width: 100%;
padding: 12px;
border: 2px solid #e2e8f0;
border-radius: 8px;
font-size: 16px;
transition: border-color 0.3s;
box-sizing: border-box;
}
.rr-input:focus, .rr-select:focus {
border-color: #4a90e2;
outline: none;
}
.rr-btn {
background-color: #4a90e2;
color: white;
padding: 15px 25px;
border: none;
border-radius: 8px;
font-size: 18px;
font-weight: 700;
cursor: pointer;
width: 100%;
transition: background-color 0.3s;
}
.rr-btn:hover {
background-color: #357abd;
}
.rr-result {
margin-top: 30px;
padding: 20px;
background-color: #f8fafc;
border-left: 5px solid #4a90e2;
border-radius: 4px;
display: none;
}
.rr-result h3 {
margin-top: 0;
color: #2d3748;
}
.rr-formula {
background: #edf2f7;
padding: 10px;
border-radius: 6px;
font-family: "Courier New", Courier, monospace;
font-weight: bold;
margin: 10px 0;
}
.rr-article {
margin-top: 40px;
padding-top: 30px;
border-top: 1px solid #e2e8f0;
}
.rr-article h2, .rr-article h3 {
color: #2c3e50;
}
function updateFields() {
var type = document.getElementById("rrType").value;
var container = document.getElementById("inputs-container");
var html = "";
if (type === "sphere") {
html = '' +
'';
} else if (type === "circle") {
html = '' +
'';
} else if (type === "ladder") {
html = '' +
'' +
'';
} else if (type === "cone") {
html = '' +
'' +
'' +
'';
}
container.innerHTML = html;
document.getElementById("rr-result-box").style.display = "none";
}
function calculateRelatedRate() {
var type = document.getElementById("rrType").value;
var resBox = document.getElementById("rr-result-box");
var outText = document.getElementById("rr-output-text");
var outForm = document.getElementById("rr-output-formula");
var v1 = parseFloat(document.getElementById("val1") ? document.getElementById("val1").value : 0);
var v2 = parseFloat(document.getElementById("val2") ? document.getElementById("val2").value : 0);
var v3 = parseFloat(document.getElementById("val3") ? document.getElementById("val3").value : 0);
var v4 = parseFloat(document.getElementById("val4") ? document.getElementById("val4").value : 0);
if (isNaN(v1) || isNaN(v2)) {
alert("Please fill in all required numeric values.");
return;
}
var result = 0;
var formula = "";
var explanation = "";
if (type === "sphere") {
// V = 4/3 pi r^3 -> dV/dt = 4 pi r^2 (dr/dt)
result = 4 * Math.PI * Math.pow(v1, 2) * v2;
formula = "dV/dt = 4πr²(dr/dt)";
explanation = "At radius " + v1 + " and a growth rate of " + v2 + " units/s, the volume is increasing at " + result.toFixed(4) + " cubic units per second.";
}
else if (type === "circle") {
// A = pi r^2 -> dA/dt = 2 pi r (dr/dt)
result = 2 * Math.PI * v1 * v2;
formula = "dA/dt = 2πr(dr/dt)";
explanation = "At radius " + v1 + " and a growth rate of " + v2 + " units/s, the area is increasing at " + result.toFixed(4) + " square units per second.";
}
else if (type === "ladder") {
if (v1 2x(dx/dt) + 2y(dy/dt) = 0 -> dy/dt = -(x * dx/dt) / y
var y = Math.sqrt(Math.pow(v1, 2) – Math.pow(v2, 2));
result = -(v2 * v3) / y;
formula = "dy/dt = -(x * dx/dt) / y";
explanation = "With a ladder of length " + v1 + " at a distance " + v2 + " from the wall, the height y is " + y.toFixed(2) + ". The top of the ladder is moving at " + result.toFixed(4) + " units/s (negative means downward).";
}
else if (type === "cone") {
if (isNaN(v3) || isNaN(v4)) { alert("Please fill all cone fields."); return; }
// V = 1/3 pi r^2 h. By similar triangles r/h = R/H -> r = (R/H)h
// V = 1/3 pi (R/H)^2 h^3 -> dV/dt = pi (R/H)^2 h^2 (dh/dt)
// dh/dt = (dV/dt) / (pi * (R/H)^2 * h^2)
var ratioSq = Math.pow(v1 / v2, 2);
result = v3 / (Math.PI * ratioSq * Math.pow(v4, 2));
formula = "dh/dt = (dV/dt) / [π * (R/H)² * h²]";
explanation = "The water level is rising at a rate of " + result.toFixed(4) + " units per second.";
}
outText.innerHTML = explanation;
outForm.innerHTML = "Calculated using: " + formula;
resBox.style.display = "block";
}
// Initialize fields
window.onload = updateFields;