Hey there PF.(adsbygoogle = window.adsbygoogle || []).push({});

I wanted to ask here if someone had any input as to why a tiny part of my code is "slow".

I have sloved a somewhat big eq.system numerically with Mathematica. Now, I do not really need the

actual integrated functions and so I sample them.

Below: I sample (picks out only 4 datapoints within each time unit) numerical values of the actual integrated functions through the use of Block and with

digits 12. I put these values into a table for interpolation later. "Solution" contains these functions

that I wish to sample, part "f" is present because I want to store for some different parameter values and "k"

denotes the index of solution function. (If you'd like, nevermind the "Joining"-part)

Print["Sampling..."];

gSolutionPart =

Table[SetAccuracy[

Block[{t = v}, Subscript[y, k][t] /. Solution[[f, 1, k]]],

12], {f, 1, diffrentb}, {k, 1, 201}, {v, i,

i + (parttime - 1/4), 1/4}];

Print["Joining..."];

If[i == 0, gSolution = gSolutionPart,

gSolution =

Table[Join[gSolution[[f, k]], gSolutionPart[[f, k]]], {f, 1,

diffrentb}, {k, 1, 201}]];

I was keeping track of the time things in my code take, and then I noticed that this sampling takes a vast

majority of time. Example: I integrate for a solution that spans a measly 10 time units. Integration took not

even 1 minute. Sampling took 9 minutes. Yay. And when I sought a solution for something more accurate over a

larger intervall, integration took ~50 minutes. I waited hours on the sampling but..

Can anyone give some tips on how to improve this without having some huge RAM spike?

I am quite the noob when it comes to coding, but I wish to learn.

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Efficient sampling of function. [Mathematica]

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads for Efficient sampling function | Date |
---|---|

MATLAB Sample Code for Monte Carlo estimation of pi | Jul 19, 2017 |

DFT matlab help | May 26, 2015 |

Mathematica: Help with creating a more efficient algorithm | Feb 23, 2011 |

MATLAB array efficiency | Feb 16, 2011 |

Efficient LaTeX for web pages? | Jan 6, 2006 |

**Physics Forums - The Fusion of Science and Community**