# Speed ​​and precision with inverse Laplace transform.

I have a problem with a Laplace inverse transform that, to me, seems a problem of precision when calculating with large / small numbers. Scientific background: I would like to calculate how photons are distributed from a light source at fixed time intervals. The light source has some internal dynamics given by a linear system of differential equations characterized by the frequency matrix Km. The emission of photons from the source is given by the matrix V. As an intermediate step in the calculation of the distribution P (n , t) of the detection of n photons in a time interval t, I need to find the inverse Laplace transform of functions with high powers in s, where s is the Laplace parameter. When I use rational numbers as input for the rates, that is, the k in Km and V, I get correct results, although the calculation takes a long time. If I insert decimal numbers, the result is clearly incorrect for n> 3. For n <3, however, the results seem correct and the calculation is faster. Does anyone have an idea of ​​how to use decimal numbers for higher powers in n and get the correct result? Alternatively, a good idea of ​​how to speed up the inverse Laplace transform with rational numbers is also welcome. Ideally, I would like to go to powers of 10 and more.

``````Clear[Km, V, G, F];

Km[kon_, koff_, kex_, kD_]: = {{- kon, koff, 0}, {kon, - (koff + kex), kD}, {0, kex, -kD}};
V[kD_, f_]: = kD f {{0, 0, 0}, {0, 0, 1}, {0, 0, 0}};
Sun[kon_, koff_, kex_, kD_, f_][s_]    : =
Reverse[(s IdentityMatrix[3] - km[kon, koff, kex, kD] + V[kD, f])];

F[kon_?NumberQ, koff_?NumberQ, kex_?NumberQ, kD_?NumberQ, f_?NumberQ][n_?NumberQ]: =
InverseLaplaceTransform[G[kon, koff, kex, kD, f][s].MatrixPower[V[V[V[V[kD, f].SUN[kon, koff, kex, kD, f][s], n], S t];
``````

Evaluating F with decimal numbers gives this

``````Absolute time[F[0.01, 0.01, 0.1, 0.01, 1][5]    /. t -> 30]{0.633334, {{-0.0000126605, -0.000313533, -0.0000102234}, {- 0.0000559714, -0.00608579, -0.0000580637}, {-0.000153185,0.00270916, 0.000255046}}}
``````

But the matrix should only have positive elements. In fact, when using rational numbers, I get the correct result.

``````Absolute time[N[F[1/100, 1/100, 1/10, 1/100, 1][5]    /. t -> 30, 5]]{1.73693, {{2.2332 * 10 ^ -11, 8.0224 * 10 ^ -10, 3.3880 * 10 ^ -9}, {8.0224 * 10 ^ -10.2.5880 * 10 ^ -8.9.9637 * 10 ^ -8}, {2.2332 * 10 ^ -10, 8.0224 * 10 ^ -9, 3.3880 * 10 ^ -8}}}
``````

The numbers are quite small, I know, and they will even be smaller for higher matrix powers, that is, n larger. Unfortunately, 1.7 seconds is too long since I need to adjust many data sets to extract the k for each of them. Clearly, 0.6 seconds are also not better light years, but at least something. Bypassing the InverseLaplaceTransfrom command in the adjustment by first calculating the transformations symbolically for different n, thus giving a set of functions, and then inserting numbers for the rates, did not speed up the adjustment, in fact, even reduced it.