I want to plot a piecewise periodic function

4 次查看(过去 30 天)
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)

采纳的回答

Walter Roberson
Walter Roberson 2021-12-24
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 个评论
Walter Roberson
Walter Roberson 2021-12-24
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 2021-12-24
yes that's exactly what i wanted to do thank you very much

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by