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
Through[Sol[s][t]]
is different fromThrough[Sol[1][t]]
, sofun[t, s]
behaves differently whens
is a symbol and when it’s numeric. $\endgroup$ParametricNDSolveValue
$\endgroup$s_?NumericQ
in the definition offun
, so thatSol[s]
would evaluate to a list before part 1 is taken. Or you could useIndexed[…, 1]
instead of…[[1]]
. You could also adde1’
to the list of expressions to return{e1, e2, e1’}
and take part 3 with NumericQ or Indexed as mentioned. $\endgroup$