# Nakafa Learning Content

> For AI agents: use [llms.txt](https://nakafa.com/llms.txt) for the site index. Markdown versions are available by appending `.md` to content URLs or sending `Accept: text/markdown`.

URL: https://nakafa.com/en/subjects/mathematics/function-modeling/piecewise-function-modeling
Source: https://raw.githubusercontent.com/nakafaai/nakafa.com/refs/heads/main/packages/contents/material/lesson/mathematics/function-modeling/piecewise-function-modeling/en.mdx

Learn how to build piecewise function models from interval boundaries, tiered rates, staged motion, and connection points.

---

## When to Use Piecewise Functions

A piecewise function is useful when one situation cannot be described well by one formula. The domain is split into intervals, and each interval uses its own rule.

For example, electricity cost can be cheaper for the first usage tier and more expensive after a certain boundary. A boundary like this is a sign that the model should be written in pieces.

### Mathematical Definition

A piecewise function can be written in the form:

```math
f(x) = \begin{cases} f_1(x), & \text{if } x \in D_1 \\ f_2(x), & \text{if } x \in D_2 \\ f_3(x), & \text{if } x \in D_3 \\ \vdots \\ f_n(x), & \text{if } x \in D_n \end{cases}
```

where $$D_1, D_2, D_3, \ldots, D_n$$ are intervals that form a partition of the function's domain.

Visible text: where are intervals that form a partition of the function's domain.

When reading or building a piecewise function, pay attention to three things:

- The formula on each row.
- The interval condition that decides when that formula is used.
- The function value at connection points, especially when an interval boundary uses $$\lt$$, $$\leq$$, $$\gt$$, or $$\geq$$.

Visible text: - The formula on each row.
- The interval condition that decides when that formula is used.
- The function value at connection points, especially when an interval boundary uses , , , or .

## Common Piece Shapes

### Linear Pieces

A linear piecewise function uses a linear function on each interval. This form often appears when the rate of change is constant for a while, then changes after a certain point.

Component: LineEquation
Props:
- title: Linear Piecewise Function
- description: Example of a linear piecewise function with three different pieces.
- data: [
{
points: Array.from({ length: 21 }, (_, i) => {
const x = -2 + i * 0.1;
return { x, y: 2 * x + 3, z: 0 };
}),
color: getColor("PURPLE"),
showPoints: false,
labels: [{ text: "y = 2x + 3", at: 10, offset: [-1.5, 1, 0] }],
},
{
points: Array.from({ length: 21 }, (_, i) => {
const x = 0 + i * 0.1;
return { x, y: -x + 3, z: 0 };
}),
color: getColor("ORANGE"),
showPoints: false,
labels: [{ text: "y = -x + 3", at: 10, offset: [1, 1, 0] }],
},
{
points: Array.from({ length: 21 }, (_, i) => {
const x = 2 + i * 0.1;
return { x, y: 0.5 * x, z: 0 };
}),
color: getColor("CYAN"),
showPoints: false,
labels: [{ text: "y = 0.5x", at: 10, offset: [1, -0.5, 0] }],
},
]
- cameraPosition: [0, 0, 12]
- showZAxis: false

The function above can be written as:

```math
f(x) = \begin{cases} 2x + 3, & \text{if } -2 \leq x < 0 \\ -x + 3, & \text{if } 0 \leq x < 2 \\ 0.5x, & \text{if } x \geq 2 \end{cases}
```

The three rows are not three separate functions. They work together as one function, and the chosen formula depends on the value of $$x$$.

Visible text: The three rows are not three separate functions. They work together as one function, and the chosen formula depends on the value of .

### Quadratic Pieces

Piecewise functions can also use quadratic pieces. This is helpful when one part of the model curves instead of following a straight line.

Component: LineEquation
Props:
- title: Combined Piecewise Function
- description: Combination of quadratic and linear functions in one piecewise function.
- data: [
{
points: Array.from({ length: 31 }, (_, i) => {
const x = -3 + i * 0.1;
return { x, y: x * x, z: 0 };
}),
color: getColor("VIOLET"),
showPoints: false,
labels: [{ text: "y = x²", at: 15, offset: [-1, -1, 0] }],
},
{
points: Array.from({ length: 31 }, (_, i) => {
const x = 0 + i * 0.1;
return { x, y: 2 * x, z: 0 };
}),
color: getColor("TEAL"),
showPoints: false,
labels: [{ text: "y = 2x", at: 15, offset: [1, -1, 0] }],
},
]
- cameraPosition: [0, 0, 12]
- showZAxis: false

## Connection Points and Continuity

### Connections Without Jumps

A piecewise function is continuous if the graph does not jump at a connection point. The value from the left, the value from the right, and the function value at that point must match.

Condition for continuity at point $$x = c$$:

Visible text: Condition for continuity at point :

```math
\lim_{x \to c^-} f(x) = \lim_{x \to c^+} f(x) = f(c)
```

Example of a continuous piecewise function:

```math
f(x) = \begin{cases} x + 1, & \text{if } x < 2 \\ 3, & \text{if } x = 2 \\ 5 - x, & \text{if } x > 2 \end{cases}
```

For continuity at $$x = 2$$:

Visible text: For continuity at :

- $$\lim_{x \to 2^-} (x + 1) = 3$$
- $$\lim_{x \to 2^+} (5 - x) = 3$$
- $$f(2) = 3$$

Visible text: - 
- 
-

### Connections With Jumps

Discontinuous piecewise functions have "jumps" or "holes" at certain points.

Component: LineEquation
Props:
- title: Discontinuous Piecewise Function
- description: Example of a function with jump discontinuity at{" "}
$$x = 1$$.
  Visible text: Example of a function with jump discontinuity at{" "}
.
- data: [
{
points: Array.from({ length: 21 }, (_, i) => {
const x = -2 + i * 0.1;
return { x, y: x + 2, z: 0 };
}),
color: getColor("ROSE"),
showPoints: false,
labels: [{ text: "y = x + 2", at: 10, offset: [-1, 1, 0] }],
},
{
points: Array.from({ length: 21 }, (_, i) => {
const x = 1 + i * 0.1;
return { x, y: 2 * x - 3, z: 0 };
}),
color: getColor("AMBER"),
showPoints: false,
labels: [{ text: "y = 2x - 3", at: 10, offset: [1, 1, 0] }],
},
]
- cameraPosition: [0, 0, 12]
- showZAxis: false

## Modeling with Piecewise Functions

### Progressive Rates

Many real-world situations can be modeled with piecewise functions because their rules change after certain boundaries. Progressive taxes, tiered parking fees, and tiered electricity rates are common examples.

**Example: Electricity Rates**

An electricity company applies tiered rates:

- $$0\text{-}50 \text{ kWh}$$: $$\text{Rp }1{,}000/\text{kWh}$$
- $$51\text{-}100 \text{ kWh}$$: $$\text{Rp }1{,}500/\text{kWh}$$
- $$>100 \text{ kWh}$$: $$\text{Rp }2{,}000/\text{kWh}$$

Visible text: - : 
- : 
- :

The mathematical model:

```math
C(x) = \begin{cases} 1000x, & \text{if } 0 \leq x \leq 50 \\ 50000 + 1500(x-50), & \text{if } 50 < x \leq 100 \\ 125000 + 2000(x-100), & \text{if } x > 100 \end{cases}
```

The number $$50{,}000$$ in the second row comes from the first $$50 \text{ kWh}$$. The number $$125{,}000$$ in the third row comes from the cost up to the first $$100 \text{ kWh}$$. This keeps the cost from restarting at $$0$$ when the usage enters a new interval.

Visible text: The number in the second row comes from the first . The number in the third row comes from the cost up to the first . This keeps the cost from restarting at when the usage enters a new interval.

**Electricity cost table:**

| Usage (kWh) | $$30$$ | $$50$$ | $$75$$ | $$100$$ | $$150$$ |
| ----------- | ------ | ------ | ------ | ------- | ------- |
| Cost (Rp)   | $$30{,}000$$ | $$50{,}000$$ | $$87{,}500$$ | $$125{,}000$$ | $$225{,}000$$ |

Visible text: | Usage (kWh) | | | | | |
| ----------- | ------ | ------ | ------ | ------- | ------- |
| Cost (Rp) | | | | | |

### Staged Speed

**Example: Multi-Modal Journey**

Someone takes a journey with:

- Walking: $$5 \text{ km/h}$$ for $$0.5 \text{ hours}$$
- Cycling: $$15 \text{ km/h}$$ for $$1 \text{ hour}$$
- Driving: $$60 \text{ km/h}$$ for $$0.5 \text{ hours}$$

Visible text: - Walking: for 
- Cycling: for 
- Driving: for

Distance function with respect to time:

```math
s(t) = \begin{cases} 5t, & \text{if } 0 \leq t \leq 0.5 \\ 2.5 + 15(t-0.5), & \text{if } 0.5 < t \leq 1.5 \\ 17.5 + 60(t-1.5), & \text{if } 1.5 < t \leq 2 \end{cases}
```

The constants $$2.5$$ and $$17.5$$ keep the total distance moving forward from the last position, instead of returning to $$0$$ when the transportation mode changes.

Visible text: The constants and keep the total distance moving forward from the last position, instead of returning to when the transportation mode changes.

## Determining Piecewise Function Equations

To determine piecewise function equations from graphs or situations:

- Split the domain at every boundary where the rule changes.
- Determine the formula for each interval.
- Check the connection points so the interval signs and function values do not conflict.
- Write all pieces in piecewise notation.

**Example:**

From a graph showing:

- Line with slope $$2$$ from $$x = -2$$ to $$x = 0$$
- Horizontal line $$y = 4$$ from $$x = 0$$ to $$x = 2$$
- Line with slope $$-1$$ from $$x = 2$$ to $$x = 4$$

Visible text: - Line with slope from to 
- Horizontal line from to 
- Line with slope from to

The solution can be summarized like this:

| Interval | Graph information | Equation |
| -------- | ----------------- | -------- |
| $$[-2, 0)$$ | Passes through $$(-2, 0)$$ with slope $$2$$ | $$y = 2(x + 2) = 2x + 4$$ |
| $$[0, 2)$$ | Horizontal line | $$y = 4$$ |
| $$[2, 4]$$ | Passes through $$(2, 4)$$ with slope $$-1$$ | $$y = -1(x - 2) + 4 = -x + 6$$ |

Visible text: | Interval | Graph information | Equation |
| -------- | ----------------- | -------- |
| | Passes through with slope | |
| | Horizontal line | |
| | Passes through with slope | |

Piecewise function:

```math
f(x) = \begin{cases} 2x + 4, & \text{if } -2 \leq x < 0 \\ 4, & \text{if } 0 \leq x < 2 \\ -x + 6, & \text{if } 2 \leq x \leq 4 \end{cases}
```

## Practice Problems

1. Determine the values of $$f(1)$$, $$f(3)$$, and $$f(5)$$ for the function:

   
   
   ```math
   f(x) = \begin{cases} x^2, & \text{if } x < 2 \\ 2x + 1, & \text{if } 2 \leq x < 4 \\ 9, & \text{if } x \geq 4 \end{cases}
   ```

2. An online taxi company applies the following rates:

   The base fare is $$\text{Rp }10{,}000$$ for the first $$2 \text{ km}$$. Km $$3\text{-}10$$ costs $$\text{Rp }4{,}000/\text{km}$$. Above $$10 \text{ km}$$, the additional rate becomes $$\text{Rp }3{,}000/\text{km}$$.

   Create a piecewise function model for the total cost!

3. Determine whether the following function is continuous at $$x = 1$$:

   
   
   ```math
   g(x) = \begin{cases} 3x - 1, & \text{if } x < 1 \\ 2, & \text{if } x = 1 \\ x + 1, & \text{if } x > 1 \end{cases}
   ```

4. Sketch the graph of the function:

   
   
   ```math
   h(x) = \begin{cases} -x + 2, & \text{if } x < 0 \\ x^2, & \text{if } 0 \leq x < 2 \\ 4, & \text{if } x \geq 2 \end{cases}
   ```

5. A worker is paid with the following system:

   The first $$8 \text{ hours}$$ are paid at $$\text{Rp }50{,}000/\text{hour}$$. Overtime from the $$9$$th hour onward is paid at $$\text{Rp }75{,}000/\text{hour}$$.

   If the maximum work is $$12 \text{ hours/day}$$, create a daily wage function!

Visible text: 1. Determine the values of , , and for the function:

 
 

2. An online taxi company applies the following rates:

 The base fare is for the first . Km costs . Above , the additional rate becomes .

 Create a piecewise function model for the total cost!

3. Determine whether the following function is continuous at :

 
 

4. Sketch the graph of the function:

 
 

5. A worker is paid with the following system:

 The first are paid at . Overtime from the th hour onward is paid at .

 If the maximum work is , create a daily wage function!

### Answer Key

1. **Calculating function values:**

   For $$f(1)$$: since $$1 < 2$$, use $$f(x) = x^2$$

   
   
   ```math
   f(1) = 1^2 = 1
   ```

   For $$f(3)$$: since $$2 \leq 3 < 4$$, use $$f(x) = 2x + 1$$

   
   
   ```math
   f(3) = 2(3) + 1 = 7
   ```

   For $$f(5)$$: since $$5 \geq 4$$, use $$f(x) = 9$$

   
   
   ```math
   f(5) = 9
   ```

2. **Taxi fare model:**

   Let $$x$$ be the distance in km, then:

   <MathContainer>
     
   
   ```math
   C(x) = \begin{cases} 10000, & \text{if } 0 < x \leq 2 \\ 10000 + 4000(x-2), & \text{if } 2 < x \leq 10 \\ 10000 + 32000 + 3000(x-10), & \text{if } x > 10 \end{cases}
   ```

   </MathContainer>

   Or simplified:

   <MathContainer>
     
   
   ```math
   C(x) = \begin{cases} 10000, & \text{if } 0 < x \leq 2 \\ 4000x + 2000, & \text{if } 2 < x \leq 10 \\ 3000x + 12000, & \text{if } x > 10 \end{cases}
   ```

   </MathContainer>

3. **Checking continuity:**

   At $$x = 1$$:

   <MathContainer>
     
   
   ```math
   \lim_{x \to 1^-} g(x) = \lim_{x \to 1^-} (3x - 1) = 3(1) - 1 = 2
   ```

     
   
   ```math
   \lim_{x \to 1^+} g(x) = \lim_{x \to 1^+} (x + 1) = 1 + 1 = 2
   ```

     
   
   ```math
   g(1) = 2
   ```

   </MathContainer>

   Since $$\lim_{x \to 1^-} g(x) = \lim_{x \to 1^+} g(x) = g(1) = 2$$, the function is **continuous** at $$x = 1$$.

4. **Sketch of graph $$h(x)$$:**

   <LineEquation
     title={
       <>
         Graph of Function $$h(x)$$
       </>
     }
     description={
       <>
         Piecewise function with three parts: decreasing linear, quadratic, and
         constant
       </>
     }
     data={[
       {
         points: Array.from({ length: 21 }, (_, i) => {
           const x = -2 + i * 0.1;
           return { x, y: -x + 2, z: 0 };
         }),
         color: getColor("PURPLE"),
         showPoints: false,
         labels: [{ text: "y = -x + 2", at: 10, offset: [0, 0.5, 0] }],
       },
       {
         points: Array.from({ length: 21 }, (_, i) => {
           const x = 0 + i * 0.1;
           return { x, y: x * x, z: 0 };
         }),
         color: getColor("ORANGE"),
         showPoints: false,
         labels: [{ text: "y = x²", at: 10, offset: [0, 0.5, 0] }],
       },
       {
         points: Array.from({ length: 21 }, (_, i) => {
           const x = 2 + i * 0.1;
           return { x, y: 4, z: 0 };
         }),
         color: getColor("CYAN"),
         showPoints: false,
         labels: [{ text: "y = 4", at: 10, offset: [0, 0.5, 0] }],
       },
     ]}
     cameraPosition={[0, 0, 12]}
     showZAxis={false}
   />

5. **Daily wage function:**

   Let $$t$$ be the working hours, then:

   <MathContainer>
     
   
   ```math
   U(t) = \begin{cases} 50000t, & \text{if } 0 < t \leq 8 \\ 400000 + 75000(t-8), & \text{if } 8 < t \leq 12 \end{cases}
   ```

   </MathContainer>

   Or simplified:

   <MathContainer>
     
   
   ```math
   U(t) = \begin{cases} 50000t, & \text{if } 0 < t \leq 8 \\ 75000t - 200000, & \text{if } 8 < t \leq 12 \end{cases}
   ```

   </MathContainer>

Visible text: 1. **Calculating function values:**

 For : since , use 

 
 

 For : since , use 

 
 

 For : since , use 

 
 

2. **Taxi fare model:**

 Let be the distance in km, then:

 <MathContainer>
 
 

 </MathContainer>

 Or simplified:

 <MathContainer>
 
 

 </MathContainer>

3. **Checking continuity:**

 At :

 <MathContainer>
 
 

 
 

 
 

 </MathContainer>

 Since , the function is **continuous** at .

4. **Sketch of graph :**

 <LineEquation
 title={
 <>
 Graph of Function 
 </>
 }
 description={
 <>
 Piecewise function with three parts: decreasing linear, quadratic, and
 constant
 </>
 }
 data={[
 {
 points: Array.from({ length: 21 }, (_, i) => {
 const x = -2 + i * 0.1;
 return { x, y: -x + 2, z: 0 };
 }),
 color: getColor("PURPLE"),
 showPoints: false,
 labels: [{ text: "y = -x + 2", at: 10, offset: [0, 0.5, 0] }],
 },
 {
 points: Array.from({ length: 21 }, (_, i) => {
 const x = 0 + i * 0.1;
 return { x, y: x * x, z: 0 };
 }),
 color: getColor("ORANGE"),
 showPoints: false,
 labels: [{ text: "y = x²", at: 10, offset: [0, 0.5, 0] }],
 },
 {
 points: Array.from({ length: 21 }, (_, i) => {
 const x = 2 + i * 0.1;
 return { x, y: 4, z: 0 };
 }),
 color: getColor("CYAN"),
 showPoints: false,
 labels: [{ text: "y = 4", at: 10, offset: [0, 0.5, 0] }],
 },
 ]}
 cameraPosition={[0, 0, 12]}
 showZAxis={false}
 />

5. **Daily wage function:**

 Let be the working hours, then:

 <MathContainer>
 
 

 </MathContainer>

 Or simplified:

 <MathContainer>
 
 

 </MathContainer>