# Solving linear equation with integrals

I have a simple equation with respect to constants A and B, unfourtunately it's written using definite integrals with unknown functions in them which are to be calculated afterwards. Mathematica is trying to process those integrals and refuses to simply solve linear equation. Is there a way to tell the system not to deal with integrals but rather consider them constant expressions?

Example:

rhs = Integrate[Plus[Times[A, x[t]], Times[B, y[t]]], List[t, 0, 1]]
Solve[rhs == A, A]


This can't be solved.

But this can:

Solve[A x[t] + B y[t] == A, A]


However those equaitons are equally simple. How do I tell mathematica to work with integrals properly and express solution in terms of those?

• Related: mathematica.stackexchange.com/a/64447/4999. Note that the linearity properties of integrals cannot be properly applied unless the resulting integrals are known to be convergent. Since A, B, x[t], and y[t] are unknown expressions, the integral should not be automatically decomposed. Some sort of manual intervention is going to be necessary, I think. – Michael E2 Mar 18 '18 at 15:58
• @MichaelE2 constants can be pulled out regardless of integral convergence. Is there a way to do so automatically? There is another problem - when integrals are quite bulky, mathematica spends a lot of time trying to evaluate before spitting them out in unchanged form. Is there away to prevent that? – Vsevolod A. Mar 18 '18 at 16:09
• You'd have to tell M that A and B are in fact constants. (One could make an assignment A = Exp[t], for instance.) However, the built-in routines for manipulating Integrate seem to ignore the attribute Constant. Algebraic manipulate of Integrate and Sum seem underdeveloped, compared to the rest of M. – Michael E2 Mar 18 '18 at 16:15
• As for M evaluating and reevaluating, the trick I used in my linked answer was to Inactivate the Integrate. Pre V-10, one can use Hold[Integrate] or HoldForm[Integrate]. – Michael E2 Mar 18 '18 at 16:15

One way is to implement a linear operator that automatically expands itself:

ClearAll[int];
int[sum_Plus, d_] := int[#, d] & /@ sum;
int[Times[c_, e__], d : {x_, a_, b_}] /; Dt[c, x] == 0 := c int[Times[e], d];

ClearAll[A, B];
SetAttributes[A, Constant];
SetAttributes[B, Constant];
Solve[rhs == A /. Integrate -> int, A] /. int :> Integrate


If you don't want to use Constant, you could live slightly more dangerously and use D instead of Dt:

ClearAll[int];
int[sum_Plus, d_] := int[#, d] & /@ sum;
int[Times[c_, e__], d : {x_, a_, b_}] /; D[c, x] == 0 := c int[Times[e], d];

ClearAll[A, B];
Solve[rhs == A /. Integrate -> int, A] /. int :> Integrate


This also works without int, but only on indefinite integrals:

rhs = Integrate[Plus[Times[A, x[t]], Times[B, y[t]]], t];
Solve[Distribute[rhs] == A, A]


Combining like integrals

rhs = Integrate[
Plus[Times[2, Derivative[1][x][t],
Plus[Derivative[1][\[Phi]][t], Times[A, Derivative[2][x][t]]]],
Times[2, Derivative[1][y][t],
Plus[Derivative[1][\[Gamma]][t], Times[A, Derivative[2][y][t]]]]],
List[t, 0, 1]];

intcombine = # /.
Plus[c_. Inactive[Integrate][a_, d_],
c_. Inactive[Integrate][b_, d_], rest___] :>
Plus[c*Inactive[Integrate][a + b, d], rest] &;

Solve[ExpandAll@rhs == A /. Integrate -> int, A] /. int :> Inactive[Integrate]
Simplify[%, TransformationFunctions -> {Automatic, intcombine}]


• For some reason, the first approach doesn't work with rhs=Integrate[Plus[Times[2, Derivative[1][x][t], \ Plus[Derivative[1][\\[Phi]][t], Times[A, Derivative[2][x][t]]]], \ Times[2, Derivative[1][y][t], Plus[Derivative[1][\\[Gamma]][t], \ Times[A, Derivative[2][y][t]]]]], List[t, 0, 1]] – Vsevolod A. Mar 18 '18 at 16:15
• Try Solve[ExpandAll@rhs == A /. Integrate -> int, A] /. int :> Inactive[Integrate]. For int to work, the integrand must be in the form of a linear combination. One could perhaps modify int to handle the expansion when all else fails. – Michael E2 Mar 18 '18 at 16:20
• That works almost perfectly. After integral is split into a lot of summands (more than necessary to pick A out), is there a way to gather them back? – Vsevolod A. Mar 18 '18 at 16:32
• @VsevolodA. Do you mean you want just one integral in (each of) the numerator and denominator of this?: i.stack.imgur.com/FKovN.png – Michael E2 Mar 18 '18 at 16:44
• @VsevolodA. Gotta run. If the updated answer doesn't address the issue, or suggest a solution to you, let me know. I'll probably be back in a few hours or so. – Michael E2 Mar 18 '18 at 16:58