# Minimizing computation time

I’m having issues with reducing the computation time of a NMinimize function. I’ve tried setting the `WorkingPrecision` and `N` and adding constraints to the variable in `NMinimize` but more or less the computation time is way too long.

`` ClearAll["`*"] \$  Assumptions = {HeavisideTheta[0] == 1, HeavisideTheta[0.] == 1,    0 < j1 <= 5, 0 < j2 <= 5, 0 < j3 <= 5, 0 < j4 <= 5, 0 < t1,    t1 <= t2, t2 <= t3, t3 <= t4, t4 <= t5, t5 <= t6, t6 <= t7} eps = 0.05 wn = 2 Pi 5  func[q_?NumericQ] :=   Module[{vmax, sol, j, a, v, x, constraint1, constraint2, constraint3,     t1, t2, t3, t4, t5, t6, t7, yofs, yoft, j1, j2, j3, j4, temp500},    j[t_] =     j1 (UnitStep[t] - UnitStep[t - t1]) -      j2 (UnitStep[t - t2] - UnitStep[t - t3]) -      j3 (UnitStep[t - t4] - UnitStep[t - t5]) +      j4 (UnitStep[t - t6] - UnitStep[t - t7]);   a[t_] = Integrate[j[t], t];   v[t_] = Integrate[a[t], t];   x[t_] = Integrate[v[t], t];   constraint1 =     FullSimplify[     a[t7], {0 < j1 <= 5, 0 < j2 <= 5, 0 < j3 <= 5, 0 < j4 <= 5,       0 < t1, t1 <= t2, t2 <= t3, t3 <= t4, t4 <= t5, t5 <= t6,       t6 <= t7}];   constraint2 =     FullSimplify[     v[t7], {0 < j1 <= 5, 0 < j2 <= 5, 0 < j3 <= 5, 0 < j4 <= 5,       0 < t1, t1 <= t2, t2 <= t3, t3 <= t4, t4 <= t5, t5 <= t6,       t6 <= t7}];   constraint3 =     FullSimplify[     x[t7], {0 < j1 <= 5, 0 < j2 <= 5, 0 < j3 <= 5, 0 < j4 <= 5,       0 < t1, t1 <= t2, t2 <= t3, t3 <= t4, t4 <= t5, t5 <= t6,       t6 <= t7}];   vmax = (j1 t1 t1 + (t3 - t2) j1 t1)/2 + (t2 - t1) j1 t1;    sol = NMinimize[{t7, {t1 j1 - j2 (t3 - t2) == 0,        j1 t1 <= 0.7, -j3 (t5 - t4) >= -0.7,        j1 t1 (t2 + t3 - t1)/2 <= 0.14, constraint1 == 0,        constraint2 == 0, constraint3 == 0.05, 0 < j1 <= 5, 0 < j2 <= 5,        0 < j3 <= 5, 0 < j4 <= 5, 0 < t1, t1 <= t2, t2 <= t3, t3 <= t4,        t4 <= t5, t5 <= t6, t6 <= t7, t7 < 2}}, {j1, j2, j3, j4, t1,       t2, t3, t4, t5, t6, t7}];   {j1, j2, j3, j4, t1, t2, t3, t4, t5, t6,      t7} = {j1, j2, j3, j4, t1, t2, t3, t4, t5, t6, t7} /. sol[[2]];   Clear[j3, j4, t5, t6, t7, t4];   j3 = q;   j4 = q;   {t4, t5, t6, t7} = {t4, t5, t6, t7} /.      NMinimize[{t7, {constraint1 == 0, constraint2 == 0,          constraint3 == 0.05, -j3 (t5 - t4) >= -0.7, t5 > t4, t6 >= t5,          t7 > t6, t4 >= t3}}, {t4, t5, t6, t7}][[2]];    yofs = -LaplaceTransform[a[t], t, s]/(s^2 + 2 eps wn s + wn^2);   yoft = InverseLaplaceTransform[yofs, s, t];   NMinimize[{N[Re[FullSimplify[yoft, t > t7]]], t > t7, t < 1.5 t7},      t, WorkingPrecision -> 9][[1]] (*Column[{NMinimize[{Re[FullSimplify[yoft, t > t7]], t > t7}, t][[1]],    Plot[Re[yoft], {t, t7, 1.5 t7}]}*)]    ] (*func[3]   func[4] *) DiscretePlot[func[q], {q, 3, 5, 0.01}]   ``

When I make the output of the function as the one in comment and call 2 individual functions the results are what I want(takes around 3 minutes to compute 2 outputs) but when I run a discrete plot, 200 calls, basically would take 5 hours which is too much. is there a way to reduce this. Using `N` or using constraints or using `WorkingPrecision` isn’t changing the computation time either.