Problem with plotting the derivative of a ParametricFunction
A straightforward but surprising approach is to specify WorkingPrecision -> $MachinePrecision
(or most any other value) in ParametricNDSolveValue
.
solution = ParametricNDSolveValue[system, y33[1], {t, 0, 1}, {δ, Γ3},
WorkingPrecision -> $MachinePrecision];
Plot[Evaluate[D[solution[δ, 1], δ] // Chop], {δ, -1, 1},
AxesLabel -> {δ, "D[y33[1][δ, 1], δ]"}]
This bizarre behavior certainly must be a bug.
Earlier workaround
A workaround is to differentiate the ODE system with respect to δ
and then solve simultaneously for y
and D[y[δ], δ]
. This is accomplished by adding to the equations in the question the following.
dS1 = D[S1, δ];
dy[t_] = {dy11[t], dy12[t], dy13[t], dy21[t], dy22[t], dy23[t], dy31[t], dy32[t], dy33[t]};
dequations = Thread[(dy'[t] - S1.dy[t]) - dS1.y[t] == 0] /. {Ω -> Γ3, Γ -> 1};
dstartConditions = Thread[dy[0] == 0];
dsystem = Join[equations, dequations, startConditions, dstartConditions];
dsolution = ParametricNDSolveValue[dsystem, dy33[1], {t, 0, 1}, {δ, Γ3}];
Plot[dsolution[δ, 1], {δ, -1, 1}, AxesLabel -> {δ, "D[y33[1][δ, 1], δ]"}]
giving the same plot as above. This approach can be applied to general parametric ODE systems, although the fact that δ
appears linearly in this ODE system is particularly convenient.
Here is a workaround:
Extract the values of the original function:
list = Table[{δ, solution[δ, 1]}, {δ, -1, 1,0.01}];
Interpolate, derivate, plot:
f = Interpolation[list];
df = D[f[x], x];
Plot[df, {x, -1, 1}]
Where df
closely approximates D[solution[δ, 1], δ]
.
As expected, the derivative is negative for $\delta <0$, and follows the form one might expect from the original plot.