TransWikia.com

How to do algebra on unevaluated integrals?

Mathematica Asked on August 17, 2021

I am working with functions calculated from a set of general basis functions.

f = a[x] + c1*b[x] + c2*c[x];
g = Expand[f*f];
h = Integrate[g, {x, -Infinity, Infinity}];

This much works fine, and I get a nice expression with products of combinations of a[x], b[x], and c[x] in the integrand. But now I need to calculate the values of c1 and c2 that optimize h and the optimal value of h. This fails:

cs = {c1, c2};
s = Solve[{D[h, #] & /@ cs == 0}, cs]
(* Solve::nsmet: This system cannot be solved with the methods available to Solve. >> *)

Is there any hack to make this work?

EVEN better would be if I could get the answer in tidy bracket notation, where for example denotes the definite integral of a[x]*b[x].

3 Answers

Similar idea to belisarius, except in V10 we can inactivate Integrate to keep it from evaluating or even trying to evaluate:

h = Inactive[Integrate][g, {x, -Infinity, Infinity}]

It is not necessary in this example, as belisarius' answer shows, but one of its intended uses is to do algebra/calculus on integrals and derivatives. Inactive can be removed easily with

Activate[h]

The function linearExpand expands its argument according to linearity properties. Factors/terms that do not depend on x are treated as constants (see update below for a more general approach).

Clear[linearExpand];
linearExpand[e_] := e //. {int : Inactive[Integrate][_Plus, _] :> Distribute[int], 
    Inactive[Integrate][integrand_Times, dom : {x_, _, _} | x_] :> 
     With[{dependencies = Internal`DependsOnQ[#, x] & /@ List @@ integrand},
      Pick[integrand, dependencies, False] *
       Inactive[Integrate][Pick[integrand, dependencies, True], dom]
      ]};

OP's sample problem:

Solve[D[h, #] == 0 & /@ cs // linearExpand, cs]

Mathematica graphics

D[h, #] == 0 & /@ cs // linearExpand

Mathematica graphics


For what it's worth...

...here's a general linearity expander. Considers factors that do not depend on x, which may be a list of symbols, as constants.

linearExpand[e_, x_, head_] := 
  e //. {op : head[arg_Plus, __] :> Distribute[op], 
    head[arg1_Times, rest__] :> 
     With[{dependencies = Internal`DependsOnQ[#, x] & /@ List @@ arg1},
      Pick[arg1, dependencies, False] head[
        Pick[arg1, dependencies, True], rest]
      ]};

Examples:

linearExpand[D[h, #] == 0 & /@ cs, x, Inactive[Integrate]]
(* same as above *)

linearExpand[foo[(a[x] + c b[y]) (2 a[x] - c b[y]) // Expand, randomarg], x, foo]
(*  -c^2 b[y]^2 foo[1, randomarg] +
     c b[y] foo[a[x], randomarg] + 
     2 foo[a[x]^2, randomarg]        *)

linearExpand[foo[(a[x] + c b[y]) (2 a[x] - c b[y]) // Expand, randomarg], {x, y}, foo]
(*  2 foo[a[x]^2, randomarg] +
    c foo[a[x] b[y], randomarg] - 
    c^2 foo[b[y]^2, randomarg]     *)

Correct answer by Michael E2 on August 17, 2021

f = a[x] + c1*b[x] + c2*c[x];
g = Expand[f*f];

(* we need to get the constants out of the integrals first*)

h = Distribute@Integrate[g, {x, -∞, ∞}] //. Integrate[q1___  r__  q2___, {v_, s__}] /; 
                                        FreeQ[{r}, v] :> r Integrate[q1 q2, {v, s}];

s= Solve[And @@ Thread[D[h, #] & /@ {c1, c2} == 0], {c1, c2}]

(* now we go to bra-ket notation *)

bkRulez = {Integrate[a_ [x] b_[x], {x, -∞, ∞}]     ->   AngleBracket[a, b], 
           Integrate[Power[a_ [x], 2], {x, -∞, ∞}] ->   AngleBracket[a, a]}
Column @@ (s /. bkRulez) // TeXForm

$$begin{array}{l} text{c1}to -frac{langle a,crangle langle b,crangle -langle c,crangle langle a,brangle }{langle b,crangle ^2-langle b,brangle langle c,crangle } text{c2}to -frac{langle b,brangle langle a,crangle -langle a,brangle langle b,crangle }{langle b,brangle langle c,crangle -langle b,crangle ^2} end{array}$$

Answered by Dr. belisarius on August 17, 2021

I played with the commands suggested above and found that Distributed[] solved the first half of the problem but only for indefinite integrals:

f = a[x] + c1*b[x] + c2*c[x];
g = Expand[f*f];
h = Distribute[Integrate[g, x]];
cs = {c1, c2};
Solve[{D[h, #] & /@ cs == 0}, cs]

I worry when my solution looks too simple... Are the more complicated answers above handling some problem I'm not aware of?

Answered by Jerry Guern on August 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP