I want to plot a piecewise periodic function

조회 수: 4 (최근 30일)
Mohammed Ayman
Mohammed Ayman 2021년 12월 24일
댓글: Mohammed Ayman 2021년 12월 24일
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