How to create a periodic function?

218 views (last 30 days)
The function at [0,2] is y=x for [0,1] and y=2-x for [1,2], I want the above function repeated at [2,10], so I need a periodic funtion in the whole [0,10], who can help me code it ,thank you.

Accepted Answer

James Tursa
James Tursa on 25 Nov 2020
Not sure what you mean by "repeated at [2,10]". Maybe this:
y = mod(x,2);
ix = y > 1;
y(ix) = 2 - y(ix);
  9 Comments
huazai2020
huazai2020 on 25 Nov 2020
Yes, you are so great,thank you so much.

Sign in to comment.

More Answers (2)

David Hill
David Hill on 25 Nov 2020
y=zeros(size(x));
for k=1:5
y(x>=(k-1)*2&x<(k-1)*2+1)=x(x>=(k-1)*2&x<(k-1)*2+1);
y(x>=2*(k-1)+1&x<2*k)=2-x(x>=2*(k-1)+1&x<2*k);
end
  4 Comments
huazai2020
huazai2020 on 25 Nov 2020
Please see the below image I upload,it is what I want.

Sign in to comment.


Setsuna Yuuki.
Setsuna Yuuki. on 25 Nov 2020
x = [0:3:36];
y = [0 1 0 1 0 1 0 1 0 1 0 1 0];
sig = pwfun(x,y);
and create the waveform only with the intersection points.

Categories

Find more on Custom Geometry and PCB Fabrication in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!