# Nakafa Framework: LLM

URL: /en/subject/high-school/11/mathematics/function-modeling/piecewise-function-modeling
Source: https://raw.githubusercontent.com/nakafaai/nakafa.com/refs/heads/main/packages/contents/subject/high-school/11/mathematics/function-modeling/piecewise-function-modeling/en.mdx

Output docs content for large language models.

---

import { getColor } from "@repo/design-system/lib/color";
import { LineEquation } from "@repo/design-system/components/contents/line-equation";

export const metadata = {
  title: "Piecewise Function Modeling",
  description: "Model real-world scenarios using piecewise functions. Learn tiered pricing, tax brackets, and multi-stage processes with step-by-step examples.",
  authors: [{ name: "Nabil Akbarazzima Fatih" }],
  date: "05/18/2025",
  subject: "Functions and Their Modeling",
};

## Understanding Piecewise Functions

A piecewise function is a function that is defined by several different equations on certain intervals of its domain. Each "piece" of the function applies to a specific part of the domain.

### Mathematical Definition

A piecewise function can be written in the form:

<BlockMath 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 <InlineMath math="D_1, D_2, D_3, \ldots, D_n" /> are intervals that form a partition of the function's domain.

**Characteristics of piecewise functions:**

- Consists of several different equations
- Each equation applies to a specific interval
- Can be continuous or discontinuous
- Intervals do not overlap

## Types of Piecewise Functions

### Linear Piecewise Functions

A linear piecewise function is a function where each piece is a linear function.

<LineEquation
  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:

<BlockMath 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}" />

### Quadratic Piecewise Functions

Piecewise functions can also contain quadratic pieces or combinations of linear and quadratic functions.

<LineEquation
  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}
/>

## Continuity of Piecewise Functions

### Continuous Piecewise Functions

A piecewise function is said to be continuous if there are no "jumps" at the connection points between pieces.

Condition for continuity at point <InlineMath math="x = c" />:

<BlockMath math="\lim_{x \to c^-} f(x) = \lim_{x \to c^+} f(x) = f(c)" />

**Example of a continuous piecewise function:**

<BlockMath 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 <InlineMath math="x = 2" />:

- <InlineMath math="\lim_{x \to 2^-} (x + 1) = 3" />
- <InlineMath math="\lim_{x \to 2^+} (5 - x) = 3" />
- <InlineMath math="f(2) = 3" />

### Discontinuous Piecewise Functions

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

<LineEquation
  title="Discontinuous Piecewise Function"
  description={
    <>
      Example of a function with jump discontinuity at{" "}
      <InlineMath math="x = 1" />.
    </>
  }
  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, such as progressive tax rates or tiered parking fees.

**Example: Electricity Rates**

An electricity company applies tiered rates:

- 0-50 kWh: Rp 1,000/kWh
- 51-100 kWh: Rp 1,500/kWh
- > 100 kWh: Rp 2,000/kWh

The mathematical model:

<BlockMath 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}" />

**Electricity cost table:**

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

### Staged Speed

**Example: Multi-Modal Journey**

Someone takes a journey with:

- Walking: 5 km/h for 0.5 hours
- Cycling: 15 km/h for 1 hour
- Driving: 60 km/h for 0.5 hours

Distance function with respect to time:

<BlockMath 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}" />

## Determining Piecewise Function Equations

To determine piecewise function equations from graphs or situations:

1. **Identify the intervals** of the domain
2. **Determine the equation** for each interval
3. **Check continuity** at connection points
4. **Write 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

Solution steps:

1. Interval 1: <InlineMath math="[-2, 0)" />

   - Passes through (-2, 0) with slope 2
   - Equation: <InlineMath math="y = 2(x + 2) = 2x + 4" />

2. Interval 2: <InlineMath math="[0, 2)" />

   - Horizontal line
   - Equation: <InlineMath math="y = 4" />

3. Interval 3: <InlineMath math="[2, 4]" />
   - Passes through (2, 4) with slope -1
   - Equation: <InlineMath math="y = -1(x - 2) + 4 = -x + 6" />

Piecewise function:

<BlockMath 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 <InlineMath math="f(1)" />, <InlineMath math="f(3)" />, and <InlineMath math="f(5)" /> for the function:

   <BlockMath 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:

   - Base fare: Rp 10,000 (for the first 2 km)
   - Km 3-10: Rp 4,000/km
   - Above 10 km: Rp 3,000/km

   Create a piecewise function model for the total cost!

3. Determine whether the following function is continuous at <InlineMath math="x = 1" />:

   <BlockMath 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:

   <BlockMath 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:

   - First 8 hours: Rp 50,000/hour
   - Overtime (9th hour onwards): Rp 75,000/hour

   If the maximum work is 12 hours/day, create a daily wage function!

### Answer Key

1. **Calculating function values:**

   For <InlineMath math="f(1)" />: since <InlineMath math="1 < 2" />, use <InlineMath math="f(x) = x^2" />

   <BlockMath math="f(1) = 1^2 = 1" />

   For <InlineMath math="f(3)" />: since <InlineMath math="2 \leq 3 < 4" />, use <InlineMath math="f(x) = 2x + 1" />

   <BlockMath math="f(3) = 2(3) + 1 = 7" />

   For <InlineMath math="f(5)" />: since <InlineMath math="5 \geq 4" />, use <InlineMath math="f(x) = 9" />

   <BlockMath math="f(5) = 9" />

2. **Taxi fare model:**

   Let <InlineMath math="x" /> be the distance in km, then:

   <div className="flex flex-col gap-4">
     <BlockMath 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}" />
   </div>

   Or simplified:

   <div className="flex flex-col gap-4">
     <BlockMath 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}" />
   </div>

3. **Checking continuity:**

   At <InlineMath math="x = 1" />:

   <div className="flex flex-col gap-4">
     <BlockMath math="\lim_{x \to 1^-} g(x) = \lim_{x \to 1^-} (3x - 1) = 3(1) - 1 = 2" />
     <BlockMath math="\lim_{x \to 1^+} g(x) = \lim_{x \to 1^+} (x + 1) = 1 + 1 = 2" />
     <BlockMath math="g(1) = 2" />
   </div>

   Since <InlineMath math="\lim_{x \to 1^-} g(x) = \lim_{x \to 1^+} g(x) = g(1) = 2" />, the function is **continuous** at <InlineMath math="x = 1" />.

4. **Sketch of graph <InlineMath math="h(x)" />:**

   <LineEquation
     title={
       <>
         Graph of Function <InlineMath math="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 <InlineMath math="t" /> be the working hours, then:

   <div className="flex flex-col gap-4">
     <BlockMath math="U(t) = \begin{cases} 50000t, & \text{if } 0 < t \leq 8 \\ 400000 + 75000(t-8), & \text{if } 8 < t \leq 12 \end{cases}" />
   </div>

   Or simplified:

   <div className="flex flex-col gap-4">
     <BlockMath math="U(t) = \begin{cases} 50000t, & \text{if } 0 < t \leq 8 \\ 75000t - 200000, & \text{if } 8 < t \leq 12 \end{cases}" />
   </div>
