Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to plot graph of this piecewise function in Methematica:

$f: [0, 1] \mapsto \mathbb{R} $

$f(x)= \begin{cases} \frac{1}{x - \frac{1}{3} } & \text{ if } x \in [0, \frac{1}{3}> \newline -1 & \text{ if } x = \frac{1}{3} \newline 18x-9 & \text{ if } x \in<\frac{1}{3}, \frac{2}{3}>\backslash \{ \frac{4}{9},\frac{5}{9} \} \newline 1 & \text{ if } x = \frac{2}{3} \newline \frac{1}{x - \frac{2}{3} } & \text{ if } x \in <\frac{2}{3}, 1] \end{cases}$

So I wrote this:

Plot[Piecewise[{{1/(x - 1/3), 0 <= x < 1/3},
    {-1, x = 1/3},
    {18 x - 9, 1/3 < x < 2/3  },
    {1, x = 2/3},
    {1/(x - 2/3), 2/3 < x <= 1}}],
       {x, 0, 1}]

Wolfram only plots the first case{1/(x - 1/3), 0 <= x < 1/3}. I figured out that the {-1, x = 1/3} and {1, x = 2/3} cases make problem. How can I write them down correctly? Thanks!

share|improve this question

closed as too localized by rm -rf Jan 29 '13 at 20:56

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
First thing to do : replace x=1/3 by x==1/3 and x=2/3 by x==2/3. –  andre Jan 29 '13 at 20:18

1 Answer 1

up vote 3 down vote accepted

You have used single-equal assignment where you meant to use double-equal comparison.

Plot[Piecewise[{{1/(x - 1/3), 0 <= x < 1/3},
                {-1, x == 1/3},
                {18 x - 9, 1/3 < x < 2/3  },
                {1, x == 2/3},
                {1/(x - 2/3), 2/3 < x <= 1}}],
     {x, 0, 1}]
share|improve this answer
    
Great. :) As in many programming languages... –  kr85 Jan 29 '13 at 20:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.