问题
When i write this in matlab
syms x;
f=x^3-cos(x);
g=diff(f)
it gives out put as
g =
3*x^2+sin(x)
Now I want to generate summation series as

I google and found "symsum" command but it doesn't do my required task, when i write the following commands
syms k
symsum(k^2, 0, 10)
symsum(1/k^2,1,Inf)
it gives the out put as
ans = 385
ans = pi^2/6
Can you guys guide me how can I genereate the series which produce output as

so that when I give command diff(Sk); it should produce result as or something like that

For example in Mathematica I can do it as

Your assistance will be surely of great help.
回答1:
I have looked the help of the symsum function and you have a really good example, try this:
syms x;
syms k real;
symsum(x^k/sym('k!'), k, 0, inf)
This commands evaluate the series


So for example, you could do the following:
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
You can declare multiple symbolic variables uk and add them up:
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}
Hope this helps,
来源:https://stackoverflow.com/questions/12875692/summation-series-using-matlab