plotting Sum function , with floor term and rectangular pulse

조회 수: 1 (최근 30일)
semicolon
semicolon 2020년 4월 21일
댓글: Ameer Hamza 2020년 4월 21일
Hey,
Is there a way to plot this function in Matlab?
y(t) =
while is the function : , and u is the Heaviside function.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 21일
편집: Ameer Hamza 2020년 4월 21일
try this
syms t n
chi = heaviside(t-n) - heaviside(t-2-n);
term = (-1)^n*floor((n+2)/2).*chi;
y = symsum(term, n, 0, inf);
t_vec = linspace(0, 10, 100);
y_vec = vpa(subs(y, t, t_vec));
plot(t_vec, y_vec, '-o')
A faster alternative:
chi = @(t, n) heaviside(t-n) - heaviside(t-2-n);
term = @(t, n) (-1).^n.*floor((n+2)/2).*chi(t,n);
y = @(t) sum(term(t, 0:ceil(t+1)));
t_vec = linspace(0, 10, 100);
y_vec = zeros(size(t_vec));
for i=1:numel(t_vec)
y_vec(i) = y(t_vec(i));
end
plot(t_vec, y_vec, '-o')
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 4월 21일
Glad to be of help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by