필터 지우기
필터 지우기

How to sum a series of functions and then plot the sum?

조회 수: 28 (최근 30일)
Shaun Pedicini
Shaun Pedicini 2018년 3월 1일
댓글: Abraham Boayue 2018년 3월 5일
This function is supposed to be able to plot a box filter:
That should possibly look like this:
I already defined t as a 1x360 double array using:
t = t = linspace(0, 4, 360)
syms k
z = symsum( (1 / k) * sin((2 * pi) * k * t ), k, 1, 10) ;
It returns a 1x360 sym variable, but I don't know how to plot it.
  댓글 수: 3
Shaun Pedicini
Shaun Pedicini 2018년 3월 1일
hmm, is there a way I can rewrite this without symbolic math? I have to admit to being very unfamiliar with Matlab as a whole.
I actually tried doing plot(t, z) after I posted this question and it looks like it works after all, though I'm not entirely sure.
Walter Roberson
Walter Roberson 2018년 3월 1일
Z = double(z);
plot(t, Z)
Your MATLAB is detecting that the input is sym and is doing the double() on your behalf, but you can make what you are doing more obvious by doing the double() yourself.

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

채택된 답변

Abraham Boayue
Abraham Boayue 2018년 3월 2일
clear variables
close all
M = 250; % The length of each function
A=3;
t = -2:4/(M-1):2;
y = zeros(1,M); % Initiallize the sum to zero
N = 100;
for k = 1:N
ck = 1/k;
y = y+ A*ck*sin(pi*k*t); % computing the sum
end
plot(t,y,'linewidth',2,'color','m')
a= title('y(t) : sum of sine wave');
set(a,'fontsize',14);
a= xlabel('x [-2\pi 2\pi]');
set(a,'fontsize',20);
a = ylabel('y');
set(a,'fontsize',20);
a = zlabel('z');
set(a,'fontsize',20);
grid;
  댓글 수: 3
Shaun Pedicini
Shaun Pedicini 2018년 3월 4일
Thanks Abraham, I hadn't given thought to scripting it like this.
Abraham Boayue
Abraham Boayue 2018년 3월 5일
My pleasure! I'm glad it worked out for you.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by