# How to calculate the derivative of the solution of ParametricNDSolveValue?

Consider the following code:

Sol = ParametricNDSolveValue[{e1'[t] == s e2[t], e2'[t] == -s e1[t],e1[0] == 1, e2[0] == 0}, {e1, e2}, {t, 0, 1}, s]
fun[t_, s_] := Through[Sol[s][t]][[1]];
Plot[fun[t, 1], {t, 0, 10}]
dfun[t_, s_] = Derivative[1, 0][fun][t, s]
Plot[dfun[t, 10], {t, 0, 1}]


The aim is to find and plot the derivative in t of fun, but I get the output:

s'[t]


and a line along the x axis as a plot, which is the wrong solution.

How do I find the derivative of the solution of ParametricNDSolveValue?

EDIT To be clear: I need to keep s as a parameter, I know that if I write dfun[t_] = D[Through[Sol[1][t]][[1]], t] I can plot the deirvative, but I do not want to fix the value of s

• Inspect the sub expressions: Through[Sol[s][t]] is different from Through[Sol[1][t]], so fun[t, s] behaves differently when s is a symbol and when it’s numeric. Jul 3 at 13:08
• @MichaelE2 I see the problem, but how do I solve it? The real aim is to use this derivative inside another ParametricNDSolveValue Jul 3 at 13:14
• You could use s_?NumericQ in the definition of fun, so that Sol[s] would evaluate to a list before part 1 is taken. Or you could use Indexed[…, 1] instead of …[[1]]. You could also add e1’ to the list of expressions to return {e1, e2, e1’} and take part 3 with NumericQ or Indexed as mentioned. Jul 3 at 13:38

sol = ParametricNDSolveValue[{e1'[t] == s e2[t], e2'[t] == -s e1[t],