HOW SHOULD DRAW THIS IN LOOP FORM? WHERE IS THE PROBLEM IN MY CODE?

1 回表示 (過去 30 日間)
HADIMARGO
HADIMARGO 2018 年 12 月 13 日
編集済み: HADIMARGO 2018 年 12 月 13 日
my code:
s=0;
for n=1:0.01:10
s=s+(-1^n+1*sin(n*pi*x));
end
f=(2/pi)*s;
plot(x,f)
Where is wrong in my code?
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 13 日
You are defining x to have only 11 points, to exist only at the integers. Your required plot is clearly defined much denser than that.
HADIMARGO
HADIMARGO 2018 年 12 月 13 日
i could do this but it is not still correct completely
4.jpg

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

採用された回答

HADIMARGO
HADIMARGO 2018 年 12 月 13 日
編集済み: HADIMARGO 2018 年 12 月 13 日
finally i could write the correct answer! hahaha
tnx guys for pushing me lonely!
x=linspace(-5,5,1000);
s=0;
for n=1:1:10000
p=((-1)^(n+1)*sin(n*pi*x))/n;
s=s+p;
end
f=(2/pi)*s;
plot(x,f)

その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 12 月 13 日
x=linspace(-5,5,10000);
s=0;
for n=1:0.01:10
s=s+(-1^n+1*sin(n*pi*x));
end
f=(2/pi)*s;
plot(x,f)
  1 件のコメント
HADIMARGO
HADIMARGO 2018 年 12 月 13 日
tnx for answering but the answer should be:
3.jpg

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by