我查看了 symsum 函数的帮助,你有一个很好的例子,试试这个:
syms x;
syms k real;
symsum(x^k/sym('k!'), k, 0, inf)
This commands evaluate the series , and actually evaluates to . As you can see you have to specify the term of the series with its dependence of 'k'. Then in the symsum command you have to specify that you want to sum over 'k' from 0 to inf.
例如,您可以执行以下操作:
syms x;
syms k real;
ak = (-1)^k*x^(2*k+1)/sym('(2*k+1)!');
sum_ak = symsum(ak, k, 0, inf); % gives back sin(x)
dak = diff(ak,x);
sum_dak = symsum(dak, k, 0, inf); % should give back cos(x), but does not
A5 = symsum(ak, k, 0, 5); % add only the first values of the series
DA5 = symsum(dak, k, 0, 5); % add the derivated terms of the series
您可以声明多个符号变量 uk 并将它们相加:
syms x;
syms k real;
n = 5;
for i = 0:n
eval(['syms u',num2str(i),' real;']);
end
A = cell(1,n);
for i=1:n
A{i} = u0;
for j=1:i
eval(['A{i} = A{i} + u',num2str(j),';']);
end
end
A{3} % check the value of A{i}
希望这可以帮助,