I have a problem where I need to calculate the cumulative definite integral and mind the min and max of the function. I believe I have set it up correctly and I have been able to compute what I need for a simple case. But during the evaluation the Mathematica kernel runs for along time and locks up my PC. I would appreciate any help or suggestion you may have to improve the code.
Clear["Global`*"];
t =.; f = 1; \[Omega] = 2 \[Pi] f; Tp = 1/f;
r = 1.;
L = 6 r;
\[Theta] = \[Omega] t;
Vd =.;
Ncyl = 3;
\[Phi][i_] := (i - 1) 2 \[Pi]/Ncyl;
Q[t_, i_] :=
r Sin[\[Theta] + \[Phi][i]] - (
r^2 Sin[\[Theta] + \[Phi][i]] Cos[\[Theta] + \[Phi][i]])/Sqrt[
L^2 - r^2 (Sin[\[Theta] + \[Phi][i]])^2];
ftot[t_] := Sum[Max[Q[t, i], 0], {i, 1, Ncyl}];
favg = Quiet@NIntegrate[ftot[t], {t, 0, Tp}, AccuracyGoal -> 2]/Tp;
Vstroke = favg Tp;
fd[t_] := ftot[t] - favg;
Plot[{ftot[t], favg, fd[t]}, {t, 0, Tp}, Frame -> True, Axes -> True,
PlotRange -> { {0, Tp}, {-1.2, 1.2}},
FrameLabel -> {"Time (sec)", "Flow rate"}, GridLines -> Automatic,
AspectRatio -> .65,
PlotStyle -> {{Red, Thickness[0.005]}, {Green,
Thickness[0.0051]}, {Blue, Thickness[0.005]}},
BaseStyle -> {FontWeight -> "Bold", FontSize -> 15,
FontFamily -> "Arial"}]
Vd[s_] := Integrate[fd[t], {t, 0, s}];
Plot[{Vd[s]}, {s, 0, Tp}, Frame -> True, Axes -> True,
FrameLabel -> {"Time (sec)", "Flow"}, GridLines -> Automatic,
AspectRatio -> .65,
PlotStyle -> {{Brown, Thickness[0.005]}, {Cyan,
Thickness[0.0051]}, {Gray, Thickness[0.01]}},
BaseStyle -> {FontWeight -> "Bold", FontSize -> 15,
FontFamily -> "Arial"}]
Vmax = MaxValue[Vd[s], s];
Vmin = MinValue[Vd[s], s];
deltav = (Vmax - Vmin)/Vstroke