I was wondering what will happen if I differentiate mod[x,1.0]. So, I tried few values:
In[38]:= Mod[x, 1.0] /. x -> 0.0
Mod[x, 1.0] /. x -> 0.3
Mod[x, 1.0] /. x -> 1.0
Mod[x, 1.0] /. x -> 1.1
Out[38]= 0.
Out[39]= 0.3
Out[40]= 0.
Out[41]= 0.1
above looks fine. and I differentiated:
In[45]:= D[Mod[x, 1.0], x] /. x -> 0.0
D[Mod[x, 1.0], x] /. x -> 0.1
D[Mod[x, 1.0], x] /. x -> 0.2
D[Mod[x, 1.0], x] /. x -> 0.3
Out[45]= -35.2121
Out[46]= 2.39809
Out[47]= 0.973623
Out[48]= 1.00005
where these values came from? I expected x is undefined where x=0,1,2,... otherwise 1.0. And results are even more unacceptable for me if I plot it!
In[49]:= Plot[Evaluate[D[Mod[x, 1.0], x]], {x, -3, 3}]
Can you explain what's wrong with my expectation(or formulation, perhaps)?
D[Mod[x, 1], x] /. x -> 0
instead. In theory,Mod[x, anyNumber]
should return $x$. and so derivative of x is 1. So you should get1
for everything. $\endgroup$ – Nasser Aug 28 '16 at 8:00Plot
. This is one of those cases where the Mathematica chooses an absurd default range for the plot.Plot[Evaluate[D[Mod[x, 1.0], x]], {x, -3, 3}, PlotRange -> All]
gives a much clearer picture. $\endgroup$ – mikado Aug 28 '16 at 11:13Mod
is basically a discrete math function, with numeric extension (documented) into the world of continuous functions. That extension is not carried through to the world of calculus, at least not in any deep way. I would advocate that one use newer functionality intended for such purposes.SawToothWave
would be the function to use in this instance. $\endgroup$ – Daniel Lichtblau Aug 28 '16 at 16:50