Inverse of Linear Function Calculator
Enter the coefficients for your linear function in the form f(x) = ax + b to find its inverse.
Result:
Steps to Find the Inverse:
f(x) = " + (b % 1 === 0 ? b : b.toFixed(4)) + ", which is a horizontal line. A horizontal line does not have a unique inverse function unless its domain is restricted.";
stepsDiv.innerHTML = "Step 1: Start with the original function: y = " + (b % 1 === 0 ? b : b.toFixed(4)) + "" +
"Step 2: Swap x and y: x = " + (b % 1 === 0 ? b : b.toFixed(4)) + "" +
"Step 3: Try to solve for y. In this case, 'y' is not present in the equation, meaning it's not possible to express 'y' in terms of 'x' uniquely. This indicates that the function f(x) = " + (b % 1 === 0 ? b : b.toFixed(4)) + " is not invertible over its entire domain.";
return;
}
var originalFunctionString = "f(x) = " + aDisplayOriginal + bDisplayOriginal;
var finalInverseDisplay = "f-1(x) = ";
if (b === 0) {
finalInverseDisplay += "x / " + aDivDisplay;
} else {
finalInverseDisplay += "(x " + bInverseDisplay + ") / " + aDivDisplay;
}
resultDiv.innerHTML = "The original function is: " + originalFunctionString + "" +
"The inverse function is: " + finalInverseDisplay + "";
// Display steps
var stepsHtml = "var the original function be y = f(x)." +
"Step 1: Write the function in terms of y:" +
"y = " + aDisplayOriginal + bDisplayOriginal + "" +
"Step 2: Swap x and y:" +
"x = " + (a === 1 ? "y" : (a === -1 ? "-y" : (a % 1 === 0 ? a : a.toFixed(4)) + "y")) + bDisplayOriginal + "" +
"Step 3: Solve the new equation for y:";
if (b !== 0) {
stepsHtml += "Subtract " + (b > 0 ? (b % 1 === 0 ? b : b.toFixed(4)) : (Math.abs(b) % 1 === 0 ? Math.abs(b) : Math.abs(b).toFixed(4))) + " from both sides:" +
"x " + bInverseDisplay + " = " + (a === 1 ? "y" : (a === -1 ? "-y" : (a % 1 === 0 ? a : a.toFixed(4)) + "y")) + "";
}
stepsHtml += "Divide both sides by " + aDivDisplay + ":" +
"y = (x " + bInverseDisplay + ") / " + aDivDisplay + "" +
"Step 4: Replace y with f-1(x):" +
"" + finalInverseDisplay + "";
stepsDiv.innerHTML = stepsHtml;
}
.calculator-container {
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
max-width: 600px;
margin: 20px auto;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.calculator-container h2 {
color: #333;
text-align: center;
margin-bottom: 20px;
}
.calculator-content p {
margin-bottom: 15px;
line-height: 1.6;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.form-group input[type="number"] {
width: calc(100% – 22px);
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 16px;
}
button {
background-color: #007bff;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
width: 100%;
box-sizing: border-box;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.result-container {
margin-top: 25px;
border-top: 1px solid #eee;
padding-top: 20px;
}
.result-container h3 {
color: #333;
margin-bottom: 10px;
font-size: 1.2em;
}
.result-output {
background-color: #e9ecef;
border: 1px solid #dee2e6;
border-radius: 4px;
padding: 15px;
margin-bottom: 15px;
word-wrap: break-word;
font-family: 'Courier New', Courier, monospace;
color: #333;
}
.result-output p {
margin: 5px 0;
}
.result-output code {
background-color: #f8f9fa;
padding: 2px 4px;
border-radius: 3px;
font-weight: bold;
}
.steps-output {
background-color: #e6f7ff;
border-color: #b3e0ff;
}
.error {
color: #dc3545;
font-weight: bold;
}
Understanding Inverse Functions and How to Find Them
An inverse function, often denoted as f-1(x), essentially "undoes" what the original function f(x) does. If a function takes an input x and produces an output y, its inverse function takes that y as an input and returns the original x. In simpler terms, if f(a) = b, then f-1(b) = a.
When Does an Inverse Function Exist?
Not all functions have an inverse. For an inverse function to exist, the original function must be one-to-one (injective). This means that every unique input x must produce a unique output y. Graphically, a function is one-to-one if it passes the horizontal line test, meaning no horizontal line intersects the graph more than once.
For example, a linear function like f(x) = 2x + 3 is one-to-one because each x value maps to a unique y value. However, a quadratic function like f(x) = x2 is not one-to-one over its entire domain (e.g., f(2) = 4 and f(-2) = 4). To find an inverse for such functions, their domain must often be restricted.
General Steps to Find an Inverse Function
The process of finding an inverse function typically involves these four steps:
- Replace
f(x)withy: Rewrite the function asy = [expression in x]. - Swap
xandy: Interchange the variablesxandyin the equation. This is the core step that conceptually "inverts" the relationship. - Solve for
y: Manipulate the new equation algebraically to isolateyon one side. - Replace
ywithf-1(x): Onceyis isolated, replace it with the inverse function notation,f-1(x).
Finding the Inverse of a Linear Function (f(x) = ax + b)
Linear functions are among the simplest to invert, provided the coefficient a is not zero. If a = 0, the function becomes f(x) = b (a horizontal line), which is not one-to-one and thus does not have a unique inverse.
Example: Find the inverse of f(x) = 2x + 3
- Replace
f(x)withy:
y = 2x + 3 - Swap
xandy:
x = 2y + 3 - Solve for
y:
Subtract 3 from both sides:x - 3 = 2y
Divide by 2:y = (x - 3) / 2 - Replace
ywithf-1(x):
f-1(x) = (x - 3) / 2
You can use the calculator above to quickly find the inverse of any linear function by entering its 'a' and 'b' coefficients.
Example 2: Find the inverse of f(x) = -0.5x - 7
Using the calculator with a = -0.5 and b = -7:
- Replace
f(x)withy:
y = -0.5x - 7 - Swap
xandy:
x = -0.5y - 7 - Solve for
y:
Add 7 to both sides:x + 7 = -0.5y
Divide by -0.5:y = (x + 7) / -0.5
(Which simplifies toy = -2(x + 7)ory = -2x - 14) - Replace
ywithf-1(x):
f-1(x) = (x + 7) / -0.5(orf-1(x) = -2x - 14)
Verifying an Inverse Function
To check if you've correctly found an inverse function, you can use the composition property: f(f-1(x)) = x and f-1(f(x)) = x. If both compositions result in x, then the functions are indeed inverses of each other.
Using our first example, f(x) = 2x + 3 and f-1(x) = (x - 3) / 2:
f(f-1(x)) = f((x - 3) / 2) = 2 * ((x - 3) / 2) + 3 = (x - 3) + 3 = xf-1(f(x)) = f-1(2x + 3) = ((2x + 3) - 3) / 2 = (2x) / 2 = x
Both compositions yield x, confirming that our inverse function is correct.