I am trying to solve numerically two differential equations with NDSolve.
Equation1 = a'[x]/a[x] - Sqrt[(1/3)*( (1/2)*(f'[x])^2 + g[f[x]] )]
Equation2 = f''[x] + 3*(a'[x]/a[x])*f'[x] + D[g[f[x]], f[x]]
where a[x]
and f[x]
are both the functions I want to get, and where I want to define g[f[x]]
as a Piecewise function of f[x]
:
g[f[x]] = Piecewise[{{f[x]^2, x0 <= x <= a1}, {-n*f[x], a1 <= x <= a2}, {f[x]^2, x >= a2}}]
where n
is a constant value.
The problem arises when I try to solve this equation numerically (let us assume e.g. x0 = 0
, a1 = 5000
, a2 = 10000
, xf = 10^6
):
nsol = NDSolve[{Equation1 == 0, Equation2 == 0, a[x0] == 1, f[x0] == K1, f'[x0] == -n*K1}, {a, f}, {x, x0, xf}, MaxSteps -> 10000000, PrecisionGoal -> 10, AccuracyGoal -> 90]
with K1
another number and n
the same before defined. (Note that I have tried to simplify my notation here used for more generality).
Unfortunately, there appears the following mistake when computing:
NDSolve::litarg: "To avoid possible ambiguity, the arguments of the dependent variable in ... should literally match the independent variables."
I have already searched for similar threads as mine unsuccesfully. My specific question is the following one: how could I solve those differential equations dependent on Piecewise
functions numerically, without needing to solve them each time for each separate interval of x
as defined in g[f[x]]
?
EQ1
andEQ2
in theNDSolve
and definedEquation1
andEquation2
. Nonetheless, we still are going to need numerical values forK
, et c. if we're going to be able to reproduce your problem (since as you probably know, changing coefficients in ODEs can drastically change how hard they are to numerically integrate.) $\endgroup$