필터 지우기
필터 지우기

MATLAB Plot Function For Sum of Series Problem

조회 수: 4 (최근 30일)
Fabio Corres
Fabio Corres 2018년 3월 2일
편집: Jan 2018년 3월 2일
Hey there,
I working on loops and draw some plots on it. When i started to work in sum of series i have found a problem for me. I cant plot what i want to draw. Here is my sum of series function :
and here is my code part :
sum=0;
for k= 1 : 1 : 10
sum = sum + ((((-1)^(k+1))+1)*cos(k*pi));
end
result = sum *2
figure(1)
plot(k,result)
end
  댓글 수: 1
Jan
Jan 2018년 3월 2일
You forgot to tell us, what you want to draw.

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

답변 (2개)

Torsten
Torsten 2018년 3월 2일
summe = zeros(11,1)
for k= 1 : 1 : 10
summe(k+1) = summe(k) + ((((-1)^(k+1))+1)*cos(k*pi));
end
result = summe *2
figure(1)
plot(0:1:10,result)
end

Jan
Jan 2018년 3월 2일
편집: Jan 2018년 3월 2일
And another approach:
AxesH = axes('NextPlot', 'add');
s = 0;
for k= 1 : 1 : 10
s = s + 2 * (((-1)^(k+1)) + 1) * cos(k*pi);
plot(k, s, 'o');
end
'NextPlot'='add' is equivalent to: hold on.
Plotting a series as a line is questionable, because there is no value except for the natural numbers.
Note: Do not use "sum" as name of a variable, because this causes troubles frequently when a user tries to call the built-in function sum() afterwards. Example:
x = 1:10;
sum(x)
sum = rand(1, 5);
sum(x)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by