How can I plot the periodic function? please help

how can I plot(t,Tg) or interpret Tg in t=(0:0.001:0.1n),n is a given positive integer ?
but it didn't work. plz help.

 採用された回答

Walter Roberson
Walter Roberson 2019 年 6 月 6 日

0 投票

Tg = 2900 * size(t);
tmod = mod(t, 0.1);
mask = tmod > 0.007;
Tg(mask) = A * exp(-B * tmod(mask));

3 件のコメント

PIN RUI HUANG
PIN RUI HUANG 2019 年 6 月 7 日
How could I plot this? I used plot(t,Tg), it showed this message:
Error using plot
Vectors must be the same length.
Torsten
Torsten 2019 年 6 月 7 日
Replace
Tg = 2900 * size(t);
by
Tg = 2900 * ones(size(t));
PIN RUI HUANG
PIN RUI HUANG 2019 年 6 月 7 日
Thanks, Torsten and Walter Robinson.

サインインしてコメントする。

その他の回答 (1 件)

mousa alsaeed
mousa alsaeed 2019 年 11 月 25 日

1 投票

here is a code for a function that can give you the plot for any periodic function first thing you need to define a variable t as symbolic variable
syms t
second thing define your function
f = log(t)-t
the function needs a period and a specific number of cycles to draw your function in
T = 3; , N = 10;
here is the code for the function :
% done by mousa alsaeed
% email : mousa276alsaeed98@gmail.com
function periodic(fun,period,number_of_cycles)
fp = 0;
syms t
for i=0:number_of_cycles-1
fp = fp + subs(fun,t,(t-i*period))*(heaviside(t-i*period)-heaviside(t-(i+1)*period));
end
fplot(fp,[0 number_of_cycles*period])
grid on
title('the periodic function')
xlabel('t')
set(gca,'XMinorTick','On','YMinorTick','On');
end
here is what you gonna write on the commmand window :
periodic(f,T,N)
and here is the results :
3.png

3 件のコメント

Nabeel Bakr
Nabeel Bakr 2020 年 7 月 21 日
編集済み: Nabeel Bakr 2020 年 7 月 21 日
Dear Mr. Mousa Alsaeed,
My B.Sc. students are doing their B.Sc. graduation project about Fourier series using Matlab platform.
We came across your nicely written Matlab code which plots any periodic function.
We would be grateful if you kindly send us a modified version of your code so that it can plot the functions starting from the negative side of x-axis (i.e. from -N/2*T to N/2*T).
We plotted the function y=x^2 (T=2) and (N=3) using different procedure. (An image is attached).
But we would like to try your code.
With our best regards.
Stay Safe.
mousa alsaeed
mousa alsaeed 2020 年 8 月 4 日
sorry for the delay
same inputs as before and here is the new code that plots periodic function to be symmetric around the y-axis (i.e. starts from -N/2*T to N/2*T)
% done by mousa alsaeed
% email : mousa276alsaeed98@gmail.com
function periodic(fun,period,number_of_cycles)
fp = 0;
syms t
for i= -number_of_cycles/2 : number_of_cycles/2
fp = fp + subs(fun,t,(t-(2*i+1)*0.5*period))*(heaviside(t-i*period)-heaviside(t-(i+1)*period));
end
fplot(fp,[(-number_of_cycles/2)*period (number_of_cycles/2)*period])
grid on
title('the periodic function')
xlabel('t')
set(gca,'XMinorTick','On','YMinorTick','On');
end
here is the results
Nabeel Bakr
Nabeel Bakr 2020 年 8 月 5 日
Thank you very much for your help ... Regards

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by