MATLAB Answers

Sum of numeric string.

15 ビュー (過去 30 日間)
Cruise
Cruise 2011 年 11 月 30 日
I have a mathematical function.This's a numeric string. How can i calculate sum of numeric string? Example: Sum of (1/3^n) with n from n to extend at infinity And what is symbol of infinity in matlab? Thanks.

  0 件のコメント

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

回答 (2 件)

Naz
Naz 2011 年 11 月 30 日
I hope you realize that computer has finite memory and can not run it forever to reach your infinity, so you gonna have to stop somewhere :). Here's what you can do:
yoursum=0;
y='1/3^n';
f=inline(y);
for x=1:1000
yoursum=yoursum+f(x);
end
yoursum

  0 件のコメント

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


Walter Roberson
Walter Roberson 2011 年 11 月 30 日
If you have the symbolic toolbox,
syms n
symsum(sym('1/3')^n, n, n, inf)
Please, though, recheck that your lower bound is really "n" just like the variable of summation. Using the same variable in both places can lead to some odd calculations. Did you perhaps mean that n should be from 1 to infinity? If so then put 1 in place of the parameter that is before infinity (the lower bound of the summation.)

  2 件のコメント

Cruise
Cruise 2011 年 11 月 30 日
This is a convergent series and i want to use convergent characteristic to calculate sumation.
syms x k
s1 = symsum(1/k^2,1,inf)
s2 = symsum(x^k,k,0,inf)
when i type this code in command window.why matlab don't show me "s1"?
Walter Roberson
Walter Roberson 2011 年 11 月 30 日
I do not know why that code would not show s1 . Unfortunately I cannot test it myself.
You could try
s1 = symsum(1/k^2,k,1,inf)

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

Community Treasure Hunt

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

Start Hunting!

Translated by