フィルターのクリア

Plotting iterations of summations using a for loop.

3 ビュー (過去 30 日間)
James Crowe
James Crowe 2017 年 10 月 26 日
コメント済み: James Crowe 2017 年 10 月 26 日
Hi all, how would I plot every iteration of the sum? It's and approximation of cos, getting closer each iteration. Thank you in advance!
x = -pi:0.1:pi
sum = 0;
n=(1:1:5);
for k = 0:n
kTerm = ((-1).^(k)).*((x.^(2.*k)))./(factorial(2.*k));
sum = sum + kTerm;
end
sum
hold on; grid on
plot (x, sum, ':b')
plot (x, ye, '-r');

採用された回答

Torsten
Torsten 2017 年 10 月 26 日
編集済み: Torsten 2017 年 10 月 26 日
x = -pi:0.1:pi;
n = 5;
sum = 0;
for k = 0:n
kTerm = ((-1).^(k)).*((x.^(2.*k)))./(factorial(2.*k));
sum = sum + kTerm;
plot(x,sum)
hold on
end
Best wishes
Torsten.
  1 件のコメント
James Crowe
James Crowe 2017 年 10 月 26 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by