periodic function with n cycles
Ältere Kommentare anzeigen
Hi, I need to create a periodic function and plot it.
F(x)=sqrt(3) + *Sin(t -2*pi/3) --> 0<t<pi/3
F(x)=Sin(t) --> pi/3 <t<2*pi/3
repeat the signal 0<t<3*pi with the period 2*pi/3 Then plot(t,Fx)
------
At the moment I use the following code
>> t1=0:.01:pi/3;
>> t2=pi/3:.01:2*pi/3;
A=sqrt(3) + sin(t1*2*pi- 2*pi/3);
B=sin(t2);
plot(t1,A,t2,B)
This method is produce the answer a one cycle. However it is quite difficult to repeat the pattern for multiple times.
Can any one n please suggest way of doing this
1 Kommentar
Image Analyst
am 8 Dez. 2013
Sounds like your homework. Is it?
Akzeptierte Antwort
Weitere Antworten (2)
Azzi Abdelmalek
am 8 Dez. 2013
t1=0:.01:pi/3;
t2=pi/3:.01:2*pi/3;
A=sqrt(3) + sin(t1*2*pi- 2*pi/3);
B=sin(t2);
t=[t1 t2],
y=[A,B]
plot(t,y)
m=5 % Repetition
n=numel(t);
tt=0:0.01:n*m*0.01-0.01
yy=repmat(y,1,m)
plot(tt,yy)
4 Kommentare
Rashmil Dahanayake
am 9 Dez. 2013
Rashmil Dahanayake
am 9 Dez. 2013
Bearbeitet: Rashmil Dahanayake
am 10 Dez. 2013
Andrei Bobrov
am 10 Dez. 2013
Bearbeitet: Andrei Bobrov
am 10 Dez. 2013
Hi Rashmil! See my variant of your problem (after ADD in my answer)
zhenning li
am 1 Nov. 2020
truely thanks,it helps a lot!
you can do it as follow:
count = 1;
for t = 0:pi/3:pi - pi/3
if mod(count, 2) == 1
x = linspace(t, t + pi/3);
y = sqrt(3) + sin(x * 2 * pi - 2 * pi/3);
plot(x, y), hold on
count = count + 1;
else
x = linspace(t, t + pi/3);
y = sin(x);
plot(x, y), hold on
count = count + 1;
end
end
Maybe following link is also helpful for you:
2 Kommentare
Rashmil Dahanayake
am 9 Dez. 2013
sixwwwwww
am 9 Dez. 2013
It was selected to choose between the plots curve should be plotted. It doesn't have effect on output actually. The output is controlled by the range in the for loop:
for t = 0:pi/3:pi - pi/3
changing pi - pi/3 to pi - pi/3 will give more periods of the plot
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!