Infinity: Indeterminate expression 0.0389874+Complexinfinity+Complexinfinity encountered

I’d like to solve 2nd order differential equation: enter image description here

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:

enter image description here

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}}] 

enter image description here

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}}];  

enter image description here

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)} 

enter image description here

But when I try to solve the Equation,

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

enter image description here

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..

enter image description here

Please help me to solve the problem.

Writing mathematical expression in a file

I am trying to write a mathematical expression as variable = expression in the output file.

The current method that I am doing is through WriteString as

expr = -((a*b*y^2*(-1 + z)*z*(1 + a*b + z))/(1 + a*b)^2) +         (z*(1 + a*b - a*b*z + (z + a*b*z)^2))/(1 + a*b)^2 -         (y*z*((-1 + z)^2 + a*b*(2 - 3*z + z^2) + a^2*b^2*(1 - z + z^2)))/(1 + a*b)^2 expression = CForm[expr] /. {Power->pow}; (*expression = CForm[HornerForm[expr]] /. {Power->pow};*) str=OpenWrite["output.hh"]; WriteString[str," double variable = ", expression,";"]; (*WriteString[str," double variable = ", ExportString[expression,"Text"]];*) Close[str]; 

The output is

 cat output.hh  double variable = -(a*b*(-1 + z)*z*(1 + a*b + z)*pow(1 + a*b,-2)*pow(y,2)) - y*z*pow(1 + a*b,-2)*(pow(-1 + z,2) + a*b*(2 - 3*z + pow(z,2)) + pow(a,2)*pow(b,2)*(1 - z + pow(z,2))) + z*pow(1 + a*b,-2)*(1 + a*b - a*b*z + pow(z + a*b*z,2)); 

I want to break the line as the original expr (or after some user-specified column say 80) i.e.

 double variable = -(a*b*(-1 + z)*z*(1 + a*b + z)*pow(1 + a*b,-2)*pow(y,2)) -                    y*z*pow(1 + a*b,-2)*(pow(-1 + z,2) + a*b*(2 - 3*z + pow(z,2)) + pow(a,2)*pow(b,2)*(1 - z + pow(z,2))) +                     z*pow(1 + a*b,-2)*(1 + a*b - a*b*z + pow(z + a*b*z,2)); 

Although this might not lead to optimized expression for numerical evaluation, however it is wanted as beautification. Also how should one optimize expression for further processing to other languages. Any suggestion? Experimental`OptimizeExpression and HornerForm are some options. Any other recommendation? MathCode is much costly 😀

Passing an expression to the Plot Function does not Work

Solving a differential equation I found that its solution was analytic, and I stored it as an expression from the default rule output of the DSolve[] function:

soleq2 = y[x] /. soleq2[[1, 1]]

Which has output:

Sqrt[x] BesselJ[Sqrt[13]/2, x] C[1] + Sqrt[x] BesselY[Sqrt[13]/2, x] C[2]

I then plotted this:

Manipulate[Plot[soleq2, {x, 0, 10}], {C[1], 0, 10}, {C[2], 0, 10}]

but the plot does not show anything, only the sliders for the modulation of C[1] and C[2]. I tried substituting these constants with other letters thinking their format might interfere with the kernel, but to no avail.

FullSimplify a expression with a even function“`Df[x] == Df[-x]“`?

I want to simplify a expression with a even functionDf[x] == Df[-x] like:

FullSimplify[-(1/2) Df[x - x4] J[x] - 1/2 Df[-x + x4] J[x], Assumptions -> {Df[x] == Df[-x]}]

This code can not give the desired result like -Df[-x + x4] J[x].

And the strange thing here is that if I replace x4 with x2, it works well.

FullSimplify[-(1/2) Df[x - x2] J[x] - 1/2 Df[-x + x2] J[x], Assumptions -> {Df[x] == Df[-x]}] will give -Df[-x + x2] J[x].

So any solutions here for x4 or arbitrary symbol?

How to add a goal in Google analytics with regular expression such as

I want to add Goal in Google Analytics with the same URL twice with a different regular expression such as

www.example.com/checkout#shipping www.example.com/checkout#payment 

these are on the same page with different tabs. So how I track user go which tab and other go where because google analytics just track my checkout page, not #shiiping and #payment

Mathematica not computing Matrix problem, just returning multiplication expression

I’m doing some very simple matrix operations in Mathematica, but for some reason, the last operation I’m trying to evaluate is not returning the actual product, just shows the symbolic multiplication.

P = { {1, 2}, {3, 4}} /10;  im = {{1},{1}} in = {{1},{1}}  A = ArrayFlatten[ { {KroneckerProduct[in\[Transpose], IdentityMatrix[2]]}, {KroneckerProduct[IdentityMatrix[2], im\[Transpose]]} } ]  p = Flatten[P] // MatrixForm  A.p 

This last operation, $ A\cdot p$ is returning the following:

enter image description here

Why is that so?

Access to Interpolation expression of Mathematica’s Interpolate command

To reproduce fits which have been done in the framework of a standard, I was reviewing the Interpolation engine of Mathematica (for InterpolationOrder -> 3) to get more information about the mechanics Mathematica is using for Interpolation.

Currently there is limited control especially for the "Hermite" Interpolation method to control the way the Splines are fitted. My interpretation is that with the "Hermite" setting the default parameter boundaries are resulting in natural Splines, whereas the PeriodicInterpolation->True setting enforces periodic boundary conditions. However there are many more methods to Spline Interpolation of 3rd order like Not-a-Knot spline or Quadratic Spline boundary conditions (see Link) Taking a simple interpolation example in Mathematica as:

data = {{0, 21}, {1, 24}, {2, 24}, {3, 18}, {4, 16}}; intf1=Interpolation[data, Method -> "Spline"]; intf2=Interpolation[data, Method -> "Hermite"]; 

I was wondering how the underlying interpolation expressions generated by the Interpolation routine could be accessed.

InputForm[intf1[[4, 1]]]  Out[1]/InputForm=  BSplineFunction[1, {{0., 4.}}, {3}, {False}, {{21., 22.61111111111111, 30.166666666666664,  13.055555555555554, 16.}, {}}, {{0., 0., 0., 0., 2., 4., 4., 4., 4.}}, {0}, MachinePrecision, "Unevaluated"] 

yields at least a BSpline function description, but intf2 hides it’s Hermite Spline implementation from the user

InputForm[intf2]  Out[2]/InputForm=  InterpolatingFunction[{{0, 4}}, {5, 3, 0, {5}, {4}, 0, 0, 0, 0, Automatic, {}, {}, False}, {{0, 1, 2, 3, 4}}, {{21}, {24}, {24}, {18}, {16}}, {Automatic}] 

Does anyone know how to get more information about the parameters resulting from Hermite Spline interpolation of order 3 in Mathematica?

Substitution of expressions in a symbolic expression

I define tables of symbolic variables in the following form (for convenience)

X = Table[Symbol["x" <> ToString[i]], {i, 1, num}]; Y = Table[Symbol["y" <> ToString[j]], {j, 1, num}];  

And after that, in cycles, I create some expressions. For example, here is one of them

Expon := Exp[ - ((X[[1]] * Y[[1]]) / 4) ];  For[i = 2, i <= num, i++,  Expon = Expon * Exp[ - ((X[[i]] * Y[[i]]) / 4)] ]  

After that, I want to act by some differential operator on my symbolic expression (let’s call it $ \Psi$ ) and substitute in the final expression some tables of numbers X1 and Y1 (here they are not symbolic, but filled by real numbers). I tried to use ReplaceAll ./ command, but it didn’t work. Could you tell me please, how can I substitute two or more tables of real numbers in symbolic expression? Long story short, how to calculate something like $ \Psi(X1, Y1)$ ?