MATLAB學習筆記:數列求和與級數
阿新 • • 發佈:2019-02-04
數列求和命令一:sum(x)
例1:
x為向量:
>> a=[1 2 3]
a =
1 2 3
>> sum(a)
ans =
6
例2:
x為矩陣:
>> b=[1 2 3;4 5 6;7 8 9]
b =
1 2 3
4 5 6
7 8 9
>> sum(b)
ans =
12 15 18
數列求和命令二:當數列的元素很有規律時
symsum(s(k),1,n)=s(1)+s(n)+……+s(n)
symsum(s(k),k,m,n)=s(m)+s(m+1)+……+s(n)
例3:
>> syms k n;
>> symsum(k,1,100)
ans =
5050
>> symsum(k^2,1,10)
ans =
385
>> symsum(k^3,k,1,n)
ans =
(n^2*(n + 1)^2)/4
>> symsum(k^4,k,1,n)
ans =
(n*(2*n + 1)*(n + 1)*(3*n^2 + 3*n - 1))/30
>> syms x n; >> symsum((-1)^(n+1)*x/(n*(n+2)),n,1,30) ans = (495*x)/1984
>> syms a k n;
>> symsum((-1)^(k)*a*sin(k),k,0,n-1)
ans =
a*((((-1)^n*exp(n*i) - 1)*i)/(2*(exp(i) + 1)) + (exp(i)*exp(-n*i)*(exp(n*i) - (-1)^n)*i)/(2*(exp(i) + 1)))
>> syms n; >> symsum(1/n^2,1,inf) ans = pi^2/6 >> syms n; >> symsum(1/n,1,inf) ans = Inf >> syms n a; >> symsum(a^n/n,n,1,inf) ans = piecewise([1 <= a, Inf], [abs(a) <= 1 and a ~= 1, -log(1 - a)])
>> syms n;
>> symsum((-1)^n,1,inf)
ans =
NaN