Finite-Sum Function

10 ビュー (過去 30 日間)
Atom
Atom 2012 年 1 月 29 日
コメント済み: Radu Trimbitas 2019 年 1 月 30 日
Hello All,
I would like to create a function S_N, that would return the Nth term of a series. Here's what I have so far:
1 function S_N = S(N)
2 k = 1:N
3 A_k = 1./(k.^(3/2)+k.^(1/2))
4 S_N = cumsum(A_k)
5 end
MatLab politely replies:
>> S_N
Error using S_N (line 2)
Not enough input arguments.
I'm not sure what else MatLab wants. I would think this is a pretty simple fix for this uber program. (I can do it perfectly on my TI89 :D)
Much Thanks, Jim

採用された回答

Andrew Newell
Andrew Newell 2012 年 1 月 30 日
S_N is the output, but the function name is S. Use, e.g.,
S(10)
(you'll need to input a number).

その他の回答 (2 件)

Jan
Jan 2012 年 1 月 30 日
You've defined S_N such that it needs one input argument. So call it like:
S_N(3)

Atom
Atom 2012 年 1 月 30 日
Much thanks;
At the bottom is my final code for anyone else that would want to know. (Of course! I have to give him a number). By the way, the infinite sum is referred to as "Theodorus' constant". It seems pretty hard to approx. Here are the first fifty digits:
1:86002 50792 21190 30718 06959 15717 14332 46665 24121 52345...
function S_N = S(N)
k = 1:N;
A_k = 1./(k.^(3/2)+k.^(1/2));
S_N = sum(A_k)
end
  2 件のコメント
Andrew Newell
Andrew Newell 2012 年 1 月 30 日
I did a quick search on Theodorus constant, and all the sources said it is the square root of 3, or 1.73205 ...
Radu Trimbitas
Radu Trimbitas 2019 年 1 月 30 日
There are two Theodorus constant, square root of 3 and sum of the series sum_{n=1}^{\infty} \frac{1}{k^{3/2}+k^{1/2}} ....

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

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by