# plotting a piecewise function

**URL:** <https://community.wolfram.com/t/plotting-a-piecewise-function/7839>\
**Category:** Questions\
**Tags:** calculus, graphics-and-visualization\
**Created:** [February 5, 2016, 4:02pm UTC](https://community.wolfram.com/t/plotting-a-piecewise-function/7839 "2016-02-05T16:02:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakeshy1998](https://avatars.discourse-cdn.com/v4/letter/r/eb8c5e/32.png) [@rakeshy1998](https://community.wolfram.com/u/rakeshy1998)\
**Post date:** [February 5, 2016, 4:02pm UTC](https://community.wolfram.com/t/plotting-a-piecewise-function/7839/1 "2016-02-05T16:02:35Z")

</div>

I want to plot a function whose domain and range is N ( natural number ) with piecewise different condition for odd and even natural number. How can I do that??

---

<div class="post-metadata">

**Author:** ![dreiss](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/dreiss/32/29094_2.png) [@dreiss](https://community.wolfram.com/u/dreiss)\
**Post date:** [February 5, 2016, 4:23pm UTC](https://community.wolfram.com/t/plotting-a-piecewise-function/7839/2 "2016-02-05T16:23:36Z")

</div>

This is not the role of the `Piecewise` function: it is more appropriate to simply use patterns in constructing your function. Here is an example:

```
f[n_Integer?EvenQ] := n 

f[n_Integer?OddQ] := (n^2) 

```

and take a look at a ListPlot of a table of values

```
ListPlot[Table[f[i], {i, 0, 10}]]

```
