# [✓] Plot a piecewise function over an interval?

GROUPS:
 Consider the following code: piecewise[{{[//function:-t^2//],[//range:-2
4 months ago
10 Replies
 . Show[Plot[Piecewise[{{-t^2, -2{{-10,10},{-4,4}}] 
4 months ago
 You don't need Show[] function: Plot[Piecewise[{{-t^2, -2 < t <= 0}, {t^2, 0 <= t < 2}}], {t, -2, 2}, PlotRange -> {{-5, 5}, {-4, 4}}] 
4 months ago
 If this is a periodic function defined on its period by: Piecewise[{{-t^2, -2 < t <= 0}, {t^2, 0 <= t < 2}}] How would I plot this waveform over the interval (-10 < t < 10)?
4 months ago
 @Stuart Symes, welcome to Wolfram Community! Please make sure you know the rules: https://wolfr.am/READ-1ST The syntax you used in your top post is NOT Wolfram Language. This forum permits only subjects related to Wolfram Technologies. Please consult Documentation and existing resources:
4 months ago
 Marco Thiel 1 Vote There are lots of ways of making this periodic: Plot[Piecewise[{{-Mod[-t, 2]^2, -2 < -Mod[t - 2, 4] <= 0}, {Mod[t, 2]^2, 0 <= Mod[t - 2, 2] < 2}}], {t, -10, 10}, PlotRange -> {{-10, 10}, {-4, 4}}] That one is not the nicest one... the definitions of the intervals is not clean.This one might work, too: Plot[Sign[#]*#^2 &[4*SawtoothWave[0.25 (x + 2)] - 2], {x, -10, 10}, PlotRange -> {All, {-4, 4}}] Cheers,MarcoPS: You might want to have a look at this:http://community.wolfram.com/groups/-/m/t/156025or thishttps://mathematica.stackexchange.com/questions/105959/changing-a-piecewise-function-into-a-periodic-functionThis one's nice, too:https://mathematica.stackexchange.com/questions/32689/how-to-plot-periodic-functions-graphicThey define: myperiodic[func_, {val_Symbol, min_?NumericQ, max_?NumericQ}] := func /. (val :> Mod[val - min, max - min] + min) Now you can do: Plot[myperiodic[Sign[x] x^2, {x, -2, 2}] // Evaluate, {x, -10, 10}] which gives the desired result.
4 months ago
 Cheers! That's what I'm after. Why wont it plot the entire plot range tho? I'm only getting (t from -8.4 to 8.4)
4 months ago
 Dear Stuart,it is much easier to answer that if you post your code and output. I suppose that the option PotRange->All might help.Cheers,Marco
 I tried the PlotRange -> ALL, no luck.Code: Plot[Piecewise[{{-Mod[-t, 2]^2, -2 < -Mod[t - 2, 4] <= 0}, {Mod[t, 2]^2, 0 <= Mod[t - 2, 2] < 2}}], {t, -10, 10}, PlotRange -> {{-10, 10}, {-4, 4}}] `