フィルターのクリア

How can i store values into an array while making summation

2 ビュー (過去 30 日間)
Zuy
Zuy 2018 年 10 月 30 日
コメント済み: Zuy 2018 年 10 月 31 日
Hi, im trying to sum this series
I want to make S(in the code) an array to keep all of values from n=N/2 to infinity. Than i will sum them up and obtain the sum of my series. My code also should do the calculation for different N values.At the and i will make a plot of Sum of my series vs N. It is shown in the image also.Thanks!
clc;
clear;
clear all;
format long
N=10:2:100;
for i=1:length(N)
for n=(N(i)/2)+1:1:10e5
S(i)=(1/n)^2;
Stot=sum(S);
end
R(i)=2*pi*Stot;
end
loglog(N,R)
  16 件のコメント
Guillaume
Guillaume 2018 年 10 月 31 日
Possibly that would work. As I don't have the symbolic toolbox, I can't help with that.
Zuy
Zuy 2018 年 10 月 31 日
Thank you so much!!

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

採用された回答

madhan ravi
madhan ravi 2018 年 10 月 30 日
Stot(i)=sum(S(i)); %use iterator as an index to avoid overwriting
also see preallocation for making code efficient
  2 件のコメント
Zuy
Zuy 2018 年 10 月 30 日
Thanks!
madhan ravi
madhan ravi 2018 年 10 月 30 日
Anytime :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by