I’d like to solve 2nd order differential equation:

Which I’d like to draw a graph of x_M and h. m, g, and M is a real constant. Cd is well defined function that has a parameter as x_M’ theta is piecewise defined function, that appears as below:

for this equation, I used code :

`\[Theta]0 = 0.5236; \[Omega]1 = 5.2359877; \[Omega]2 = 1.396; t1 = \[Theta]0 / \[Omega]1; t2 = \[Theta]0 / \[Omega]2; T=2*(t1+t2); f[t_]=Piecewise[{{ -Mod[t,T]*\[Omega]1 ,0<=Mod[t,T]<t1},{ -\[Theta]0+((Mod[t,T]-t1)*\[Omega]2), t1<=Mod[t,T]<(t1+2t2)},{\[Theta]0-((Mod[t,T]-t1-2t2)*\[Omega]1),(t1+2t2)<=Mod[t,T]<T}}] `

It is clear that derivative of the function is

`thetaprime[t_]:=Piecewise[{{-5.2359877 ,0<=Mod[t,T]<t1},{ 1.396, t1<=Mod[t,T]<(t1+2t2)},{-5.2359877,(t1+2t2)<=Mod[t,T]<=T}}]; `

for differential equation, I used a code

`initconds = {x[0] == 0, x'[0] == 0.00001, h[0] == (M + m)/(\[Rho]*A), h'[0] == 0} eqns = {m Cos[\[Theta][t]] Sin[\[Theta][t]] h''[t] + (M + m (Sin[\[Theta][t]]^2)) x''[t] == - Cd[Derivative[1][x][t]] *h[t]* Derivative[1][x][t] + m Sin[\[Theta][t]] (g Cos[\[Theta][t]] + r thetaprime[t]^2),( -M-(m*Cos[\[Theta][t]]^2))*h''[t] - m Cos[\[Theta][t]] Sin[\[Theta][t]] x''[t] == -g M + A g \[Rho] h[t] - m Cos[\[Theta][t]] (g Cos[\[Theta][t]] + r thetaprime[t]^2)} `

But when I try to solve the Equation,

`sol = NDSolve[Append[eqns, initconds], {x, h}, {t, 0, tf}, Method -> {"DiscontinuityProcessing" -> False}] `

It gives following three errors. I can’t understand why these errors occur.

Infinity::indet: Indeterminate expression 0.0389874 +ComplexInfinity+ComplexInfinity encountered.

Infinity::indet: Indeterminate expression -0.160636+ComplexInfinity+ComplexInfinity+ComplexInfinity+ComplexInfinity+ComplexInfinity encountered.

NDSolve::ndnum: Encountered non-numerical value for a derivative at t == 0..

Please help me to solve the problem.