# Help Making a Piecewise Function Periodic

57 views (last 30 days)
Connor Buternowsky on 24 Sep 2022
Commented: Paul on 10 Oct 2022
So I am trying to plot a piecewise function where z(t) = {t , 0 <= t < 1
e^(-5(t-1)) , 1 <= t < 2.5
0 , else
When I run it, it just gives the one period even though mod(t,2.5) should be keeping everything OK. How do I fix this? (I want to make it periodic)
(Oh yeah, my interval is -2 <= t <= 12)
t1 = -2 : 0.01 : 12;
syms t z(t); % defining a symbolic variable
z(t) = (piecewise((mod(t,2.5)>=0)&(mod(t,2.5)<1),t, (mod(t,2.5)>=1)&(mod(t,2.5)<2.5), exp(-5.*(t-1)), 0));
z1 = z(t1);
figure
hold on
plot(t1, z1);

Paul on 24 Sep 2022
HI Connor,
Something like this?
syms t real
z(t) = piecewise(0 <= t <= 1,t, 1 < t <= 2.5, exp(-5*(t-1)),0);
fplot(z(t),[-2 12])
z1(t) = z(mod(t,2.5));
fplot(z1(t),[-2 12])
tval = -2:.01:12;
plot(tval,z1(tval))
Paul on 10 Oct 2022
You'll need to show the exact code you ran and the results obtained before going any further.

### Categories

Find more on Assumptions in Help Center and File Exchange

R2022b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!