2
$\begingroup$

I'm simulating some transient data for fast Fourier transform -- on the order of 20 million points. Understandably MM takes a while to do this.

Are the any techniques in table generation optimisation when dealing with such large numbers? Or is this just a computational limit I have to accept?

This is my current attempt:

MyFunction[VMax_, Tau_, t_] := VMax Sin[2 Pi t] Exp[-t/Tau];
TransientData = Table[MyFunction[t],{t,0,60,3*10^-6}]
$\endgroup$
3
  • 1
    $\begingroup$ @HenrikSchumacher I'll add the function to make the question more complete. I wasn't sure how relevant the function would be. $\endgroup$
    – user27119
    Commented Feb 13, 2019 at 14:17
  • 1
    $\begingroup$ Ping me when you are ready. $\endgroup$ Commented Feb 13, 2019 at 14:17
  • $\begingroup$ @HenrikSchumacher Ping. Typical values for VMax = 1E-7, Tau = 400. $\endgroup$
    – user27119
    Commented Feb 13, 2019 at 14:20

1 Answer 1

6
$\begingroup$
VMax = 1. 10^-7;
Tau = 400.;
MyFunction[VMax_, Tau_, t_] := VMax Sin[2 Pi t] Exp[-t/Tau];

You exforce that a great part of the compuations is performed in exact arithmetic which is just slow. Since the function MyFunction is built from elementary and vectorized functions, we may exploit that by applying it to the list instead of looping over it with Table. Here is a timing example; notice the introduction of decimal dots at critical positions:

n = 200000;
TransientData = Table[MyFunction[VMax, Tau, t], {t, 0, 60, 60/(n - 1)}]; // 
  AbsoluteTiming // First
TransientData1 = MyFunction[VMax, Tau, Subdivide[0., 60., n - 1]]; // 
  AbsoluteTiming // First

Max[Abs[TransientData - TransientData1]]

1.84223

0.004158

4.06758*10^-14

$\endgroup$
2
  • 1
    $\begingroup$ +1 There should be a space in the definition of VMax, i.e., VMax=1. 10^-7 or use VMax=10.^-7 $\endgroup$
    – Bob Hanlon
    Commented Feb 13, 2019 at 15:30
  • $\begingroup$ Good point @Bob. Thank you. $\endgroup$ Commented Feb 13, 2019 at 16:06

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.