How to Do Piecewise in Desmos

How to Do Piecewise in Desmos

How to Do Piecewise in Desmosを失敗せずに実践するためのおすすめの方法をピックアップして解説します。

Piecewise functions are just functions with a split personality. They behave one way before a certain point, and a completely different way after. In Desmos, the secret weapon is the curly brace {}.

Think of it like this: Desmos speaks math, but you have to whisper in its ear with the right syntax. You don’t need to write long, messy conditional statements. You just need to tell it: "Hey, for this range of x, use this formula." And then add another brace for the next range.

The basic formula looks like this: y = {condition1: formula1, condition2: formula2}. That’s it. No magic spells, no hidden menus. Seriously, try it right now—open Desmos and type it in.

Your First Piecewise: The "Temperature Check"

Let’s say you want a graph that stays at y = 1 if x is less than 0, then jumps to y = 2 when x is 0 or more. That’s a simple step function. Type this into a new expression line: y = {x < 0: 1, x >= 0: 2}.

Boom. You see a horizontal line at 1, then a sudden jump to 2. Desmos automatically plots the gap or the closed dot depending on your inequality (yes, it’s that smart). Notice I used < and >=—you can use any standard inequality sign.

Side note: I once spent ten minutes wondering why my graph was blank. Turns out, I typed a comma instead of a colon. Commas separate the pieces; colons create the condition and the output pair. Don’t be that person.

Adding More than Two Pieces

You can have as many pieces as you want, like a mathematical Frankenstein’s monster. For example, a function that’s x + 1 when x is less than -2, 3 when x is between -2 and 2, and x - 1 when x is greater than 2.

Desmos to graph Piecewise Functions and Evaluate with Function NotationDesmos to graph Piecewise Functions and Evaluate with Function Notation

Type: y = {x < -2: x + 1, -2 <= x < 2: 3, x >= 2: x - 1}. Desmos handles the overlapping conditions like a pro—just make sure your intervals don’t accidentally argue (like having the same x value in two different pieces).

Pro tip: If you’re doing a piecewise that uses a variable from a slider (like a), you can animate it. Imagine a graph that changes its behavior as you slide a number. It’s like watching a slow-motion train wreck, but in a beautiful way.

阿部 裕樹
Author

阿部 裕樹

マネー知識やキャリア形成に役立つノウハウを、初心者にも分かりやすく解説するのが得意です。