# Evaluation Control of a recursive function inside Piecewise

Posted 8 months ago
1359 Views
|
4 Replies
|
2 Total Likes
|
 Please, How to do Evaluation Control in order to let a function "FC[t]" be evaluated recursively to define a Piecewise function, BUT, after this evaluation, save the new Piecewise function "pwtemp", so that, each time "pwtemp" are called, "FC[t]" are NOT evaluated again?Please see notebook below. When I tried to define "pwtemp" as the Piecewise function with the "FC[t]" inside, it was not possible to Plot what I wanted. But, when I used the Plot function directely with the Piecewise construction, it was possible to Plot the function I want. I want to define "pwtemp" in function of "t" and easily evaluate this function resulting in the values shown in the second Plot result (vertical axis). When I tried to evaluate "pwtemp" using the code below, it returned 0, and it is not what I wanted.
4 Replies
Sort By:
Posted 8 months ago
 You should give the variable t to pwtemp[t_]:=....Instead of Count, which does not play well with calculus, you may try an integral of DiracDelta: With[{vti = Range, Vscc = 3/2}, Integrate[Sum[DiracDelta[x - pt], {pt, vti}], {x, t - Vscc, t}, Assumptions -> Element[t, Reals]]] /. HeavisideTheta -> UnitStep % // PiecewiseExpand 
Posted 8 months ago
 Thank you Gianluca, but let me explain the intention: I have a list with the times that some events occurred in a timeline from 0 to 10 years: vti = {0.5, 1.5, 2.4, 3, 4.1...}; Considering a moving time window with fixed width (w=1.5), I want to sum the total nr. of events inside the time window, in function of time t;
Posted 8 months ago
 Hi Andre,I think Gianluca is right about the definition of pwtemp ClearAll@pwtemp; pwtemp[t_] := Piecewise[{{0, t < Vscc}, {FC1[t], Vscc ⩽ t < 2 Vscc}, {FC2[t], 2 Vscc ⩽ t < m}}]; Plot[pwtemp[t], {t, 0, m}, PlotRange -> Full, Filling -> Axis, PlotTheme -> "Detailed", PlotLegends -> Definition@pwtemp] Posted 8 months ago
 Thanks Rohit, This worked for "pwtemp" plot, but the only problem is that when I try to create another function that is a multiplication of another Piecewise function with this new pwtempt], the Integrate function seems not to understand tthat the variable "t" is for the two. See this another question that I have posted >>[here<<.