1
$\begingroup$

I have to find a plot of an integral function that contains an integral function, but the running time is too slow. Here is the code:

H = 0.07358;
Ω = 0.75;
Λ = Ω*3*H;
lE = 3.79*10^-4;
l = 13.778128047493817;
k = 1;
    
a[t_?NumericQ] := ((1 - Ω)/Ω)^(1/3)*Sinh[(3*H*Sqrt[Ω]*t)/2]^(2/3)            
f[t_?NumericQ] := -((1/(5*Sqrt[Cosh[Sqrt[3 Λ]/2*t]^2]))*
            ((-8*Hypergeometric2F1[-(1/2), 5/6,
              11/6, -Sinh[Sqrt[3 Λ]/2*t]^2] + (4 + Cosh[2*Sqrt[3 Λ]/2*t])*Hypergeometric2F1[1/2, 5/6, 11/6, -Sinh[Sqrt[3 Λ]/2*t]^2])*Sinh[Sqrt[3 Λ]/2*t]^(2/3)))        
β[t_?NumericQ] := Sin[k*(l - t)]        
Z[t_?NumericQ] := β[t]*f[t]        
ft[t_?NumericQ] := -((Sqrt[Λ] Cosh[1/2 Sqrt[3] Sqrt[Λ] t] (-8 Hypergeometric2F1[-(1/2), 5/6, 11/6, -Sinh[1/2 Sqrt[3] Sqrt[Λ]t ]^2] + (4 + Cosh[Sqrt[3] Sqrt[Λ] t]) Hypergeometric2F1[1/2, 5/6, 11/
               6, -Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^2]))/(5 Sqrt[3] Sqrt[Cosh[1/2 Sqrt[3] Sqrt[Λ] t]^2] Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^(
           1/3))) + (Sqrt[3] Sqrt[Λ] Cosh[1/2 Sqrt[3] Sqrt[Λ] t] (-8 Hypergeometric2F1[-(1/2), 5/6, 11/6, -Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^2] + (4 + Cosh[Sqrt[3] Sqrt[Λ] t]) Hypergeometric2F1[1/2, 5/6, 11/6, -Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^2]) Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^(5/3))/(10 (Cosh[1/2 Sqrt[3] Sqrt[Λ]t]^2)^(3/2)) - 1/(5 Sqrt[Cosh[1/2 Sqrt[3] Sqrt[Λ] t]^2])
        Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^(2/3) (1/(2 Sqrt[3])
           5 Sqrt[Λ] (4 + Cosh[Sqrt[3] Sqrt[Λ] t]) Coth[1/2 Sqrt[3] Sqrt[Λ] t] (-Hypergeometric2F1[1/2, 5/6, 11/6, -Sinh[ 1/2 Sqrt[3] Sqrt[Λ] t]^2] + 1/Sqrt[
            1 + Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^2]) - 1/Sqrt[3] 20 Sqrt[Λ] Coth[1/2 Sqrt[3] Sqrt[Λ] t] (-Hypergeometric2F1[-(1/2), 5/6, 11/6, -Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^2] + Sqrt[1 + Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^2]) + Sqrt[3] Sqrt[Λ] Hypergeometric2F1[1/2, 5/6, 11/6, -Sinh[1/2 Sqrt[3] Sqrt[Λ] t]^2] Sinh[Sqrt[3] Sqrt[Λ] t])
at[t_?NumericQ] := (H Sqrt[Λ] ((1 - Ω)/Ω)^(1/3) Cosh[3/2 H Sqrt[Λ] t])/Sinh[3/2 H Sqrt[Λ] t]^(1/3)
Zt[t_?NumericQ] := ft[t]*β[t]    
h[t_?NumericQ] := (H Sqrt[Λ] (-1 + Ω^(-1))^(1/3) Coth[(3 H Sqrt[Λ] t)/2])/((1 - Ω)/Ω)^(1/3)      
βz[t_?NumericQ] := β'[t]        
Zz[t_?NumericQ] := f[t]*βz[t]        
k1z[t_?NumericQ] := NIntegrate[(2*Zt[y]/a[y]) - Zz[y]/a[y]^2, {y, l, t}, Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule", 
        "SymbolicProcessing" -> 0}, PrecisionGoal -> 1]    
F[t_?NumericQ] := NIntegrate[k1z[y], {y, l,t}, 
      Method -> {"GlobalAdaptive", Method -> "GaussKronrodRule", 
        "SymbolicProcessing" -> 0}, PrecisionGoal -> 1]

Plot[F[t], {t, lE, 1}, PlotStyle -> Black ] // AbsoluteTiming

These are quite oscillating functions. The evaluation of k1z[t] takes 3.71 seconds, and I never get a result for the integration of k1z[t], that is F[t].

How could I speed up this integration? I think that the problem is due to the difficulty of the expression. Is there a way to improve my code?

$\endgroup$

1 Answer 1

1
$\begingroup$

after deleting a superfluous closing square bracket in function ft

(4 + Sqrt[3] Sqrt[\[CapitalLambda]] t])

the plot appears after about 7 seconds, but I have no idea of the correctness of your formulas... Is

Zt[\[Lambda]_?NumericQ] := ft[t]*\[Beta][t]

really a function of [Lambda] ?

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Sorry! Yes, there was an error in the code. Now I correct it. $\endgroup$ Commented May 1, 2023 at 15:54

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.