Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm using the following function

f[t_] := 
  3/4 t^-3 NIntegrate[(x^4*Csch[x/2]^2), {x, 0, t}, 
    Method -> {Automatic, "SymbolicProcessing" -> 0}];

I have to apply large lists against it as well as use it in fitting routines like NonLinearModelFit. I can already significantly reduce the evaluation time by switching off the SymbolicProcessing option. Is there any other way to speed up the evaluation of f significantly?

A close to real-case example would be the following:

data = Table[250/t, {t, 0.1, 3000, 0.1}];
f /@ data; // AbsoluteTiming

For sure, the minimum and maximum argument of the function would be {0.001, 100000}.

//Edit

Sorry for the confusion about Min,Max arguments. The range can vary, but in the worst case Min,Max of data is {0.001, 100000}. Therefore any simplification has to yield the correct result within that Range.

//Edit2

Symbolical Integration would be perfect, but due to the PolyLog functions, relative errors become very large, especially for t>1000 and very small t. Also for me this is even more time consuming.

f[t_?NumericQ] :=  3 t^-3 NIntegrate[(x^4 Exp[x])/(Exp[x] - 1)^2, {x, 0, t}, Method -> {Automatic, "SymbolicProcessing" -> 0}]
h[t_] = 3/4 t^-3 Integrate[x^4 Csch[x/2]^2, {x, 0, t}, Assumptions -> t \[Element] Reals && t > 0]
LogLogPlot[{Abs[h[x] - f[x]]/f[x], 10^-4}, {x, 0.001, 100000}, PlotRange -> Full]
LogLinearPlot[{Abs[h[x] - f[x]]/f[x], 10^-4}, {x, 0.001, 100000}]
data = Table[250/t, {t, 0.1, 3000, 0.1}];
f /@ data; // AbsoluteTiming
h /@ data; // AbsoluteTiming

I would like to have the relative error less than 10^-4.

share|improve this question
    
You say "For sure, the minimum and maximum argument of the function would be {0.001, 100000}.", where I take "it" to refer to f. But the arguments of f are taken from data and Min[data] == data[[-1]] == 0.0833333, while Max[data] == data[[1]] == 2500., Can you resolve the discrepancy for me. –  m_goldberg Jun 27 at 6:27
    
You can symbolically integrate once and for all using f[t_] = 3/4 t^-3 Integrate[x^4 Csch[x/2]^2, {x, 0, t}, Assumptions -> t \[Element] Reals && t > 0], which makes your numerical integration superfluous. –  Stephen Luttrell Jun 27 at 8:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.