I don't have experience in Mathematica and I would like to use the ability it has to do symbolic computations to find the terms of a series of functions recursively. The terms I want to find are given by:
$$S_{n+1}(x,t)=i\int_0^{t}\left(\frac{\partial^2S_n(x,\tau)}{\partial{x^2}}-A_n(x,\tau)\right)d\tau$$ $$A_n(x,t)=\sum_{i=0}^nS(x,t)_{i}S(x,t)_{n-i}$$
I have written the following:
S[0, x_, t_] = Exp[-(x)^2]
A[0, x_, t_] = S[0, x, t]*S[0, x, t]
S[n_Integer, r_, t_] :=
S[n, r, t] =
Refine[Block[{e},
I*Integrate[
1/(2) D[S[n - 1, r, e], {r, 2}] - A[n - 1, r, e], {e, 0, t}]],
Assumptions ->
Element[r | t | \[Sigma] | l | \[Alpha] | \[Beta], Reals]];
A[n_Integer, y_, t_] :=
A[n, y, t] =
Refine[Sum[S[i, y, t]*S[n - i, y, t], {i, 0, n}],
Assumptions ->
Element[y | t | \[Sigma] | l | \[Alpha] | \[Beta], Reals]];
SN[n_Integer, r_, t_] := Sum[S[i, r, t], {i, 0, n}]
h = SN[5, r, t]
However, when I use this type of construction for more complicated equations or when I want to get higher-order terms, the running time starts to be of the order of hours. Is there a way to make this code more optimized?
Thank you all in advance.
n_integer
. Also, the first "S" function do not depend on the variable "t". $\endgroup$S
andSn
,A
andAn
, to avoid recurring errors/calls to the same function. $\endgroup$