I want to plot a piecewise periodic function

4 vues (au cours des 30 derniers jours)
Mohammed Ayman
Mohammed Ayman le 24 Déc 2021
Commenté : Mohammed Ayman le 24 Déc 2021
The fundmental period and i can't really make it periodic
t1=linspace(-2,0);
func1=t1+2;
t2=linspace(0,1);
func2=-2.*t2+2;
X=[func1 func2];
t=[t1 t2];
plot(t,X)

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Déc 2021
You are defining the concatenation of two individual periodic functions, which gets you two y for each x.
t1 = @(t) mod(t,2)-2;
func1 = @(t) t1(t)+2;
t2 = @(t) mod(t,1);
func2 = @(t) -2.*t2(t) + 2;
X = @(t) [func1(t); func2(t)];
T = linspace(-5, 5);
plot(T, X(T))
You should consider using logical masks, such as
(mod(t,3) < 2) .* t1(mod(t,3)-2) + (mod(t,3) >= 2) .* t2(mod(t,3)-2)
  3 commentaires
Walter Roberson
Walter Roberson le 24 Déc 2021
Yes -- but should you?
Or is the idea that you want something of period 3 with the first 2/3 of it being controlled by t1, and the last third controlled by t2 ?
t1 = @(t) mod(t,2)-2;
func1 = @(t) t1(t)+2;
t2 = @(t) mod(t,1);
func2 = @(t) -2.*t2(t) + 2;
X = @(t) func1(t) + func2(t);
T = linspace(-5, 5);
plot(T, X(T))
Mohammed Ayman
Mohammed Ayman le 24 Déc 2021
yes that's exactly what i wanted to do thank you very much

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by