# Can I use countroots with an Interpolating Function?

I want to count the number of roots of an interpolating function that is the result of a system of differential equations (that were solved numerically using NDSolve).

m = 0.142;
r = 0.025;
I2 = (4*m*r^2)/5;
I1 = I3 = (14*m*r^2)/5;
g = 10;
u = 0.01;
V0 = 3;
p = 1.3;
Cd = 0.4;
b = 100;
sol2 = NDSolve[{I2*(ϕ'[t] + ψ'[t]*Sin[θ[t]])*ψ'[t]*Cos[θ[t]] -
I1*(ψ'[t])^2*Cos[θ[t]]*Sin[θ[t]] -
2*m*g*r*Cos[θ[t]] - I1*θ''[t] == 0,
-(I2*θ'[t]*Cos[θ[t]]*(ϕ'[t] + ψ'[t]*Sin[θ[t]]) -
I2*Sin[θ[t]]*(ϕ''[t] + ψ''[t]*Sin[θ[t]] + ψ'[t]*θ'[t]*
Cos[θ[t]]) - I3*(Cos[θ[t]])^2*ψ''[t] +
2*I3*ψ'[t]*θ'[t]*Sin[θ[t]]*
Cos[θ[t]]) == +m*(g + r*Cos[θ[t]]*θ''[t] -
r*Sin[θ[t]]*(θ[t])^2)*r*u*Cos[θ[t]]*
Tanh[10^5*(ψ'[t] - ϕ'[t])] -
8.31 ((p*Cd*r^5)/(2 π))*3*(ψ'[t])^2,
-I2 (ϕ''[t] + ψ''[t]*Sin[θ[t]] + ψ'[t]*θ'[t]*
Cos[θ[t]]) == -m*(g + r*Cos[θ[t]]*θ''[t] -
r*Sin[θ[t]]*(θ[t])^2)*r*u*Cos[θ[t]]*
Tanh[10^5*(ψ'[t] - ϕ'[t])],
ψ[0] == 0, ϕ[0] == 0, θ[0] == ArcSin[2/5 - g/((b)^2*r)],
ψ'[0] == b, ϕ'[0] == b, θ'[0] == 2.0},
{ψ, ϕ, θ, ψ', ϕ', θ'}, {t,0, 100}]

interpFN = θ'[t] /. First@sol2
CountRoots[interpFN[t], {t, 0, 1}]


The CountRoots command appears to not work with an interpolating function. How can I make this work ?

• Use WhenEvent to collect zeros. – Alex Trounev Apr 15 at 20:44