I want to plot a piecewise periodic function
10 views (last 30 days)
Show older comments
Mohammed Ayman
on 24 Dec 2021
Commented: Mohammed Ayman
on 24 Dec 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)
0 Comments
Accepted Answer
Walter Roberson
on 24 Dec 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 Comments
Walter Roberson
on 24 Dec 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))
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!