I want to plot a piecewise periodic function

4 Ansichten (letzte 30 Tage)
Mohammed Ayman
Mohammed Ayman am 24 Dez. 2021
Kommentiert: Mohammed Ayman am 24 Dez. 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)

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 24 Dez. 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 Kommentare
Walter Roberson
Walter Roberson am 24 Dez. 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 am 24 Dez. 2021
yes that's exactly what i wanted to do thank you very much

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by