# problem in solving a non linear differential equation

I'm trying to reslove a differential equation with one of the coefficents depending on the dependent variable, it's a simple dynamic system, with one of the coefficients that can assume 2 values: The model I have to solve is a classic mass-spring-damper model, but the spring has two values, the first is when the spring is compressed (k) and the second is when the spring is stretched and depend on a coefficient that represent the level of damage of the system (alp). Here is the code that iI wrote

    Model[X_, t_, f1_, f2_, T_, m_, c_, k_, alp_] :=
Module[{L = Log[f2/f1], Mol}, If[X <= 0, Mol = k, Mol = k - alp*k];
Return[m X''[t] + c X'[t] + Mol X[t] ==
Sin[2*Pi*f1*T/L*(Exp[t/T*L] - 1)]]];

fCamp = 563;
T = 8.86;
step = 1/fCamp;
fMin = 2.25;
fMax = 225;
Mas = 1;
Smorz = 2;
Mol = 20000;
Dann = 0.45;
sol =
NDSolve[{Model[x, t, fMin, fMax, T, Mas, Smorz, Mol, Dann],
x == 0, x' == 0}, x, {t, 0, 10},
, MaxStepSize -> step]


But NDSolve gives me this error:

NDSolve::nlnum: The function value {1.28415*10^-9,0.000210658 -1.27571*10^-14 Mol\$33139} is not a list of numbers with dimensions {2} at {t,x[t],(x^\[Prime])[t]} = {0.0000149012,1.27571*10^-14,1.28415*10^-9}.


Can someone help me? The purpose of this program is to solve the differential equation:

mx''[t]+cx''[t]+k(x[t])x[t]=F[t]

with k(x[t]):=If(x<=0,k',k'(1-alp))


Given the nature of this differential equation, Non linear behaviour should be showed.

• You should execute Model[x, t, fMin, fMax, T, Mas, Smorz, Mol, Dann] to see what ode you are integrating. It's not clear to me what you want, but it is clear to me that the error is in the If[..] statement. Specifically, X <= 0 will never be true and never be false, because X is just the symbol x, which is not a number. Possibly you might make Mol be Piecewise[{{k, x[t] <= 0}}, k - alp*k] and get what you want. – Michael E2 Dec 30 '20 at 4:05
• Thanks for the tip, now NDSolve works without errors, but the result is one of a linear equation – Cft Dec 30 '20 at 11:31

## 1 Answer

Here's what I suggested in my comment:

Model[X_, t_, f1_, f2_, T_, m_, c_, k_, alp_] :=

Module[{L = Log[f2/f1]},
Return[
m X''[t] + c X'[t] +
Piecewise[{{k, X[t] <= 0}}, k - alp*k] X[t] ==
Sin[2*Pi*f1*T/L*(Exp[t/T*L] - 1)]]];

fCamp = 563;
T = 8.86;
step = 1/fCamp;
fMin = 2.25;
fMax = 225;
Mas = 1;
Smorz = 2;
Mol = 20000;
Dann = 0.45;
ode = Model[x, t, fMin, fMax, T, Mas, Smorz, Mol, Dann]
(* same form as desired
Piecewise[{{20000, x[t] <= 0}}, 11000.]*x[t] + 2*x'[t] + x''[t] ==
Sin[27.1988426138371*(-1 + E^(0.5197709013530578*t))]
*)

sol = NDSolve[{ode, x' == 0}, x, {t, 0, 10}, MaxStepSize -> step];

ListLinePlot[x /. sol, PlotRange -> {{0, 2}, Automatic}] The OP seems to complain (or not?) that the result is are "linear." Let's examine:

ode /. x -> (\[Alpha]*x[#] &) // Simplify The alpha in the Piecewise coefficient shows that the equation will have characteristics of a linear system for positive values of α but not for negative ones.

If it were linear, this would form of a basis of the homogeneous system:

solIVP[x0_, p0_] :=
NDSolveValue[{ode, x == x0, x' == p0}, x, {t, 0, 10},
MaxStepSize -> step]

b1 = solIVP[1, 0][t] - x[t] /. sol;
b2 = solIVP[0, 1][t] - x[t] /. sol;


The following confirms the linearity in three cases for α b1 + β b2 with α and β nonnegative (the spikes are due to numerical error where the denominator vanishes, but the plots are otherwise constant):

test1 = solIVP[2, 0][t] - x[t] /. sol;
test2 = solIVP[0, 3][t] - x[t] /. sol;
test3 = solIVP[2, 3][t] - x[t] /. sol;
Plot[{test1/b1, test2/b2, test3/(2 b1 + 3 b2)}, {t, 0, 2},
PlotRange -> {0, 4},
PlotLegends -> {"test1", "test2", "test3"}] The following shows it is not linear when α is negative:

test = solIVP[-2, 0][t] - x[t] /. sol;
Plot[test/b1, {t, 0, 2}, PlotRange -> 3] • First thing first, happy new year. Sorry if I seemed disrespectful with my previos comment. I must Thank you for your answer, it has been very useful, and for the linearity, I messed up during the final review, so, yes, it's unlinear. Thank you, I can only admire such competence. – Cft Jan 1 at 16:04