3
$\begingroup$

I have an expression of the form

a Integrate[b[t], {t, 0, x}]

and I would like to take the coefficient $a$, save it to a list, take the $b(t)$ out of the integral, and save it to a different list. $b(t)$ could be

Exp[-2 t^2] t^(9/5) (-t + x)^(4/5) HypergeometricPFQ[{1/2, 1}, {7/5, 19/10}, -3 t^2]

The idea is that Mathematica can't do the integration because of the complexity of $b(t)$, but there's a trick that has to be implemented manually on $b(t)$ and then it works.

To extract the coefficient I understand I have to use some sort of Coefficient or CoefficientList except we don't have a power anymore. To extract out $b(t)$ I understand First@Integrate[b[t], {t, 0, x}] would work but I think the coefficient in front messes it up.

I'm not really good with patterns and I appreciate any help. Thanks!

$\endgroup$

2 Answers 2

4
$\begingroup$

With

exp = a Integrate[b[t], {t, 0, x}]

a and b can be extracted by

exp[[1]]
(* a *)
exp[[2, 1]]
(* b[t] *)

Note: Use AppendTo to add either result to a preexisting list.

Addendum

In answer to a comment below, suppose,

exp = 3 5 a e Integrate[7 b[t] g[t], {t, 0, x}];

If you do not mind the 3 and 5 multiplied together, then

Cases[exp, Except[_Integrate], {1}]
(* {15, a, e} *)

If you do mind, then use

deferexp = Defer[3 5 a e Integrate[7 b[t] g[t], {t, 0, x}]];
Cases[deferexp, Except[_Integrate] , {2}]
(* {3, 5, a, e} *)

Note that FullForm and TreeForm can be useful in determining where particular terms are in an expression, although the output can be voluminous.

$\endgroup$
1
  • $\begingroup$ Thanks @bbgodfrey! If, by chance, you had another constant out front c, then is there a way to lump all constants together so calling exp[[1]] would give a c? $\endgroup$
    – Buddhapus
    Commented Aug 17, 2016 at 4:00
1
$\begingroup$
Extract[HoldForm[
  a Integrate[
    Exp[-2 t^2] t^(9/5) (-t + x)^(4/5) HypergeometricPFQ[{1/2, 
       1}, {7/5, 19/10}, -3 t^2], {t, 0, x}]], {{1, 1}, {1, 2, 1}}]

Use HoldForm to block evaluation and use Extract to take out the part you want.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.