Real World Problem

A taxi service charges a $3.00 base fee plus $2.00 per mile. Let m be the number of miles. Write an expression for the total cost.

$3
Fixed Fee
Constant (Intercept)
+
$2
×
m
Variable Rate
Rate × Miles
=
2m + 3
Total Cost Equation

Modeling Linear Equations

Many real-world costs follow a specific pattern: a starting fee plus a rate based on usage. Let's model a taxi ride mathematically.
Continue

1. The Base Fee (b)

The taxi charges $3.00 just to get in. This is a FIXED cost because it doesn't change no matter how far you go. In algebra, this is often 'b'.
Continue

2. The Variable Rate (m)

Next, we have the cost that changes: $2.00 per mile. If you go 'm' miles, the variable cost is 2 * m. This is the rate of change.
Continue

3. Total Cost Expression

Combine them! Total Cost = (Rate × Miles) + Base Fee. So we get '2m + 3'. This is the classic linear equation format: y = mx + b.
Continue

Practice & Code

Try modeling a delivery fee scenario below. Mastering this pattern allows you to write function logic for pricing, scoring, and more.
Continue

Linear Calculation in Code

This "mx + b" pattern appears everywhere in programming. From animation progress to subscription pricing.

calculateRideCost.js
function getTaxiCost(miles) {
  const baseFee = 3.00;      // Fixed (b)
  const ratePerMile = 2.00;  // Rate (m)
  
  // y = mx + b
  return (ratePerMile * miles) + baseFee;
}

// 10 mile ride: (2 * 10) + 3
console.log(getTaxiCost(10)); // Output: 23
Implementing Linear Equation
AlgoAnimator: Interactive Data Structures