使用Matlab的求和系列 [英] Summation series using matlab

查看:111
本文介绍了使用Matlab的求和系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在matlab中写这个

When i write this in matlab

syms x;
f=x^3-cos(x);
g=diff(f)

它发出为

g =

g =

3 * x ^ 2 + sin(x)

3*x^2+sin(x)

现在我想将求和序列生成为

Now I want to generate summation series as

我用Google搜索并找到了"symsum"命令,但是当我编写以下命令时,它没有完成我所需的任务

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)

它给出的输出为

ans = 385

ans = 385

ans = pi ^ 2/6

ans = pi^2/6

你们可以指导我如何生成产生以下结果的系列吗?

Can you guys guide me how can I genereate the series which produce output as

这样,当我给出命令diff(Sk)时;它应该产生这样的结果

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

例如在Mathematica中,我可以按照

For example in Mathematica I can do it as

您的帮助肯定会给您很大的帮助.

Your assistance will be surely of great help.

推荐答案

我已经看过symsum函数的帮助,并且您有一个非常好的示例,请尝试以下操作:

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)

此命令评估系列,实际上评估为.如您所见,您必须指定序列项的相关性"k".然后,在symsum命令中,必须指定要对从0到inf的'k'求和.

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.

例如,您可以执行以下操作:

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

您可以声明多个符号变量uk并将它们加起来:

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}

希望这会有所帮助,

这篇关于使用Matlab的求和系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆