# How can I graph a piecewise function in Desmos?

**URL:** <https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874>\
**Category:** Questions\
**Created:** [April 28, 2023, 7:00pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874 "2023-04-28T19:00:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederick](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Frederick](https://cl.desmos.com/u/Frederick)\
**Post date:** [April 28, 2023, 7:00pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874/1 "2023-04-28T19:00:14Z")

</div>

Hi everyone, I’m currently trying to graph a piecewise function in Desmos, but I’m not quite sure how to do it. The function I’m working with is f(x) = { 2x + 1 if x ≤ 0, 4x - 3 if x \> 0 }. I’ve tried entering it as two separate functions, but that doesn’t seem to work. I also tried using the “piecewise” function in Desmos, but I’m not sure how to properly format it. Can anyone help me with this? Thanks in advance!  
[easeus data recovery crack download](https://www.crackshere.com/easeus-data-recovery-wizard-crack/)

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [April 28, 2023, 7:36pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874/2 "2023-04-28T19:36:44Z")

</div>

```auto
f(x)={x<=0:2x+1, 4x-3}

```

[Example](https://www.desmos.com/calculator/abw9tvwyy0)

This can be extended to additional pieces, where you have {condition 1:expression 1, condition 2:expression 2, … , “otherwise” expression}

---

<div class="post-metadata">

**Author:** ![slgotting](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@slgotting](https://cl.desmos.com/u/slgotting)\
**Post date:** [May 24, 2024, 4:53pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874/8 "2024-05-24T16:53:18Z")

</div>

Also if your function gets complicated, use this notation:

f(x) = x + 1 { x \< 0 }

and simply add more lines. This makes it easier to read imo

---

<div class="post-metadata">

**Author:** ![jhavens1566](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/jhavens1566/32/5309_2.png) [@jhavens1566](https://cl.desmos.com/u/jhavens1566)\
**Post date:** [July 9, 2024, 3:08pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874/9 "2024-07-09T15:08:40Z")

</div>

You can also use a combination of min max and ceil functions. I was running into limitations where you couldn’t define a default outer function such as -1 \> x \> 1. Also trying to add the pieces together resulted in nothing being returned.

The solution I came up with

```auto
f(x) = |x| max(min(ceil(|a-x|-b),1),0)
g(x) = x^2 max(min(ceil(b-|a-x|),1,0)
f(x) + g(x)

```

where a defines the function center and b defines the width.  
when a = 0 and b = 1:  
f(x) would be -1 \> x \> 1 and  
g(x) would be -1 \< x \< 1.

You can also remove the absolute value to get ie x\>1 or x\<1 etc.

 ![Screenshot_20240709-090519](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/3/3be1a78b0e4f080bb4c1b7049045d032636cfaa5.png)

 ![Screenshot_20240709-090755](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/7/7d2efa76458241ff00457d63680a531aa495eb87.png)

---

<div class="post-metadata">

**Author:** ![Coolfishy101](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/coolfishy101/32/7023_2.png) [@Coolfishy101](https://cl.desmos.com/u/Coolfishy101)\
**Post date:** [May 20, 2025, 3:24pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874/10 "2025-05-20T15:24:22Z")

</div>

Hello, I don’t know if you still need this but there is a function called join where you can input two or more functions together as one function in this notation f(x) = join(g(x),h(x)) where g(x) and h(x) are defined with their own parameters in different lines. Its useful for things like function composition

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [May 20, 2025, 5:29pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874/11 "2025-05-20T17:29:34Z")

</div>

`join()` is actually a list function, so what you’ve done here is essentially create a list of functions equivalent to the following:

```auto
f(x) = [g(x), h(x)]

```

---

<div class="post-metadata">

**Author:** ![Donathan](https://avatars.discourse-cdn.com/v4/letter/d/91b2a8/32.png) [@Donathan](https://cl.desmos.com/u/Donathan)\
**Post date:** [March 7, 2026, 5:33pm UTC](https://cl.desmos.com/t/how-can-i-graph-a-piecewise-function-in-desmos/4874/12 "2026-03-07T17:33:45Z")

</div>

I don’t know if you still need this, but this is how to do piecewise functions.

 ![Screenshot 2026-03-06 1.59.23 PM](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/6/6cc6b5cf23429f2f2b56cfe25398f9d0dc50aa7a.png)
