There is one more problem with your code: Count
does not play well with symbolic manipulation:
Clear[f];
f[t_] := Count[{1, 2, 3}, x_ /; (t - 2) \[LessSlantEqual] x < t];
f[3]
f[t] /. t -> 3
This means that your functions FC1
, FC2
and those built with these, must be calculated only with numerical values of t
. If you feed them a symbolic value, they give nonsensical results. Here is a reworking of your code that corrects for the problem:
pwPA[t_] =
Piecewise[
Partition[
Riffle[vf,
Table[
vti[[i]] \[LessSlantEqual] t < vti[[i + 1]], {i, 1, ni + 1}]],
2]];
pwtemp1[t_] =
Piecewise[{{pwPA[t - Vscc],
Vscc \[LessSlantEqual] t < 2 Vscc}, {pwPA[t - f Vscc],
2 Vscc \[LessSlantEqual] t < m}}];
FC1[t_?NumericQ] :=
Count[vti, x_ /; (t - Vscc) \[LessSlantEqual] x < t];
FC2[t_?NumericQ] :=
Count[vti, x_ /; (t - f Vscc) \[LessSlantEqual] x < t];
pwtemp2[t_?NumericQ] :=
Piecewise[{{PSA^FC1[t],
Vscc \[LessSlantEqual] t < 2 Vscc}, {PSA^FC2[t],
2 Vscc \[LessSlantEqual] t < m}}];
pwPAMV[ut_?NumericQ] := pwtemp1[ut] pwtemp2[ut];
pl1 = Plot[pwtemp1[tt], {tt, 0, m}, PlotRange -> Full, Filling -> Axis]
NIntegrate[pwtemp1[tt], {tt, 0, m}]/m
pl2 = Plot[pwPAMV[tt], {tt, 0, m}, PlotRange -> Full,
Filling -> Axis]
NIntegrate[pwPAMV[tt], {tt, 0, m}]/m
In a previous post I suggested using DiracDelta
instead of Count
. That would allow symbolic manipulation.