Calculaing the table of values for function defined as an infinie series

1 回表示 (過去 30 日間)
I need this code below to caluate the sum of the first 50 terms of the series :t to the power n for t value. That is, a kind of table of values for the series for t=1:10 It gives the error message: ??? Error using ==> power Matrix dimensions must agree. Please someone help % Calculating the sum of an infinite series
t =1:10;
n=0:50;
E(1,:)= sum(t.^n)

採用された回答

Jos
Jos 2014 年 7 月 19 日
編集済み: Jos 2014 年 7 月 19 日
you can use a for loop to do this
t = 1:10;
n = 0:50;
for i=1:length(t)
E(1,i)=sum(t(i).^n);
end
Cheers
Joe
  4 件のコメント
Chuzymatics Chuzymatics
Chuzymatics Chuzymatics 2014 年 7 月 20 日
Try plotting t versus E values and the figure won't match your expectation. I mean write/run: t=1:10; y = [E(1), E(2), . . . E(10)]; plot(t, y)
Jos
Jos 2014 年 7 月 20 日
Both the method above and the one below by Roger (a lot more elegant by the way) produce exactly what you would expect
E:
51
2.25e+15
1.08e+24
1.69e+30
1.11e+35
9.70e+38
2.10e+42
1.63e+45
5.80e+47
1.11e+50
plotting E in the way you try to do will basically only show the last point as it is a lot bigger than the other points, try plotting the y axis on a logarithmic scale using semilogy(t,E), you'll get this graph

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

その他の回答 (1 件)

Roger Stafford
Roger Stafford 2014 年 7 月 19 日
Also you can use this:
E = sum(bsxfun(@power,1:10,(0:50)'),1);
  4 件のコメント
Roger Stafford
Roger Stafford 2014 年 7 月 20 日
編集済み: Roger Stafford 2014 年 7 月 20 日
A Side Note: The value of your E(10) would be 1111...11, a string of fifty-one 1's in decimal, if it were computed exactly. This reminds me of one of the Fifty-Eighth Putnam Exam questions which posed the intriguing problem: "Let N be the positive integer with 1998 decimal digits, all of them 1; that is, N = 1111...11. Find the thousandth digit after the decimal point of the square root of N." (Surprisingly, it is solvable without using a computer.)
Chuzymatics Chuzymatics
Chuzymatics Chuzymatics 2014 年 7 月 21 日
Many thanks

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

カテゴリ

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