EdisonKIng
EdisonKIng

Reputation: 29

How to exchange integration and summation operator in Maple?

I want to integrate a function expanded by a series as below:

Eq1:=int(x*f(x),x);
subs(f(x) = sum(l[i](x)*f(x[i]), i = 0 .. n), Eq1);

Then I want to do the integration first, followed by summation, is there any Maple command to do that?

'sum(f(x[i])*int(l[i](x)*x, x), i = 0 .. n)';

enter image description here

I want to exchange the calculation procedure of integration and summation in Maple.

Upvotes: 1

Views: 134

Answers (1)

acer
acer

Reputation: 7271

Let's construct a procedure that will turn an integral of a sum into a sum of an integral.

G := proc(IS) local ig;
  uses IntegrationTools;
  ig := GetIntegrand(IS);
  op(0,ig)(op(0,IS)(op(1,ig),op(2..,IS)),
                    op(2..,ig));
end proc:

Now, your example.

It's a very bad idea to use indexed names x[i] within an integral whose variable-of-integration is x. I've changed x[i] to X[i].

Eq1 := int(x*f(x),x):
new := subs(f(x) = sum(l[i](x)*f(X[i]), i = 0 .. n),
            Eq1);

     int(x*sum(l[i](x)*f(X[i]),i = 0 .. n),x)

Bring the factor x inside the sum, to get that form of an integral of a sum.

temp := combine(new);

     int(sum(x*l[i](x)*f(X[i]),i = 0 .. n),x)

Now apply G to it,

ans := G(temp);

     sum(int(x*l[i](x)*f(X[i]),x),i = 0 .. n)

You may prefer that the factor f(X[i]) is outside the integral.

IntegrationTools:-Expand(ans);

     sum(f(X[i])*int(x*l[i](x),x),i = 0 .. n)

The procedure G is re-usable. We can now easily apply it to any subexpression (of a larger expression) that is of the form of an integral of a sum.

This works whether we have "active" int and sum or inert Int and Sum. It also preserves any extra arguments, and handles definite as well as indefinite integrals.

Eq2 := 1/Int(x*g(x),x=a..b) + foo + int(x*f(x),x);

new2 := subs(f(x) = sum(l[i](x)*f(X[i]), i = 0 .. n),
             g(x) = Sum(l[i](x)*g(X[i]), i = 0 .. n),
             Eq2):

temp2 := subsindets(new2,specfunc({int,Int}),combine):

Apply G to any subexpression that is an integral of a sum.

ans2 := subsindets(temp2,
                   And(specfunc({int,Int}),
                       satisfies(u->type(op(1,u),
                         specfunc({sum,Sum})))),
                   G);

    1/Sum(Int(x*l[i](x)*g(X[i]),x = a .. b),i = 0 .. n)
    + foo
    + sum(int(x*l[i](x)*f(X[i]),x),i = 0 .. n)

Bring the factors g(X[i]) and f(X[i]) outside the integrals.

IntegrationTools:-Expand(ans2);

    1/Sum(g(X[i])*Int(x*l[i](x),x = a .. b),i = 0 .. n)
    + foo
    + sum(f(X[i])*int(x*l[i](x),x),i = 0 .. n)

Upvotes: 1

Related Questions