Help Making a Piecewise Function Periodic

70 visualizaciones (últimos 30 días)
Connor Buternowsky
Connor Buternowsky el 24 de Sept. de 2022
Comentada: Paul el 10 de Oct. de 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);

Respuesta aceptada

Paul
Paul el 24 de Sept. de 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))
  4 comentarios
Anoop Kiran
Anoop Kiran el 10 de Oct. de 2022
Hi Paul,
I tried your code, unfortunately it doesn't result in the periodic behavior at every 2.5 interval like the second and third plots that you have.
Paul
Paul el 10 de Oct. de 2022
You'll need to show the exact code you ran and the results obtained before going any further.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by