0
$\begingroup$

Suppose I have a polynomial

$a_0+a_1 f(x,t) + a_2 f(x,t)^2 + ....$.

In code,

a0 + a1 y + a2 y^2 + a3 y^3 /. y :> Integrate[Subscript[y, k] E^(I k y), k]
a0 + 
a1 Integrate[E^(I k y) Subscript[y, k], k] + 
a2 Integrate[E^(I k y) Subscript[y, k], k]^2 + 
a3 Integrate[E^(I k y) Subscript[y, k], k]^3

I want to replace $f$ with $\int f_k(t) e^{ik x}dk$. The problem that I am facing is that when I use the replace rule, I get

$\qquad a_0+a_1 \int f_k(t) e^{ikx}dk + a_2 (\int f_k(t) e^{ikx}dk)^2 + ....$

on and on. Is there a way to sort integration variable such that I get

$\qquad a_0+a_1 \int f_{k_1}(t) e^{ik_1x}dk_1 + a_2 (\int f_{k_1}(t) e^{i{k_1}x}dk_1)(\int f_{k_2}(t) e^{i{k_2}x}dk_2) + ...$

automatically? Assume I can't fiddle with the code to generate these polynomials. Similarly let's say I have collected 3rd order terms which would look like

$\qquad \sum_i\hat L_i[f(x,t)]\hat K_i[f(x,t)]\hat T_i[f(x,t)],$

where $\hat L, \hat K , \hat T$ are some operators. Is there also ways to plug in the Fourier transformation of f so that the integration variables are automatically sorted?

$\endgroup$
  • 1
    $\begingroup$ Posts without proper example code (that is copypastable) tend to be frowned upon. Please edit your question and add appropriate code examples. $\endgroup$ – ciao May 9 at 22:50
  • $\begingroup$ Welcome to Mma.SE. Start by taking the tour now and learning about asking and what's on-topic. Always edit if improvable, show due diligence, give brief context, include minimal working example of code and data in formatted form. By doing all this you help us to help you and likely you will inspire great answers. The site depends on participation, as you receive give back: vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$ – rhermans May 10 at 15:39
  • $\begingroup$ You should avoid using Subscript while defining symbols (variables). Subscript[x, 1] is not a symbol, but a composite expression where Subscript is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doing Set[Subscript[x, 1], 2] which is to assign a DownValues to the operator Subscript and not an OwnValues to an indexed x as you may intend. Read how to properly define indexed variables here $\endgroup$ – rhermans May 10 at 15:39
  • 1
    $\begingroup$ @rhermans Not to mention it makes the code very hard to read. $\endgroup$ – MelaGo May 10 at 18:52
2
$\begingroup$

Pattern matching can help here.

a0 + a1 y + a2 y^2 + a3 y^3 /. 
{a_ y :> 
   a Integrate[Subscript[y, Subscript[k, 1]] E^(I Subscript[k, 1] y), Subscript[k, 1]], 
 a_ y^n_ :> 
   a Times @@ Table[Integrate[Subscript[y, Subscript[k, sub]] E^(I Subscript[ k, sub] y), Subscript[k, sub]], {sub, 1, n}]}

$\text{a0}+\text{a1} \int e^{i k_1 y} y_{k_1} \, dk_1+\text{a2} \left(\int e^{i k_1 y} y_{k_1} \, dk_1\right) \int e^{i k_2 y} y_{k_2} \, dk_2+\text{a3} \left(\int e^{i k_1 y} y_{k_1} \, dk_1\right) \left(\int e^{i k_2 y} y_{k_2} \, dk_2\right) \int e^{i k_3 y} y_{k_3} \, dk_3$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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