Reini
Reini

Reputation: 1281

Mathematica: Use Piecewise instead of If

I have this periodic defined function via "If":

T = 1;

Tt[t_] := Quotient[t, T]*T
f[t_] := If[t >= Tt[t] && t < ((Tt[t] + T/2)), 1, -1]

I need to redefinie it with "Piecewise". My try looks like this:

g[t_] := Piecewise[{
        {1, (t >= Tt[t] && t < ((Tt[t] + T/2)))}
    },
    -1
];

If I Plot f[t] I get this perfect periodic graph. If I Plot g[t] I get a dashed line at y=1 and a other dashed line at y=-1 (shifted to the other one).

It looks like mathematica plots the pieces of the function correct but does not connect the pieces.

Upvotes: 1

Views: 1009

Answers (1)

b.gatessucks
b.gatessucks

Reputation: 1242

You can use :

Plot[{g[t]},{t,-5,5}, Exclusions->None]

Upvotes: 4

Related Questions