I have solved a SDE with ParametricNDSolve:
s = ParametricNDSolve[
{p1, m1, p0, m0}, {P, m}, {r, 0, 1}, {m, k, e, Cnew}
]
And now I want to treat the parameters m, k, e, Cnew
as variables because I want to evaluate conditions like P[m, k, e, Cnew][1] == 0
.
How can I plot the condition (for example) P[m, k, 1, 1][1] == 0
?
I have tried doing:
f[r_, m_, k_, e_, Cnew_] := Evaluate[P[m_, k_, e_, Cnew_][r] /. s]
But, using NSolve
(with k = 1
, for example):
NSolve[f[1, m, 1, 1, 1] == 0, m]
I get: {}
I have also done the plot for k=1
:
Plot[f[1, m, 1, 1, 0] , {m, 0, 11}]
getting good results for k=1
.
Edit:
Runnable code with a simpler example:
p1 = P'[r] == -m*r + k*r^2;
p0 = P[0] == 1;
s = ParametricNDSolve[{p1, p0}, {P}, {r, 0, 1}, {m, k}];
f[r_, m_, k_] := Evaluate[P[m, k][r] /. s]
NSolve[f[r, 1, 1] == 0, r] (*That's ok*)
NSolve[f[1, m, 1] == 0, m] (*But this...*)
NSolve[f[1, m, k] == 0, m] (*And this... that is what I really want*)
Plot[f[1, m, 1], {m, 0, 5}] (*But this works!*)
I'm searching the expression m = m(k) from f[1, m, k] == 0
FindRoot
?NSolve
is built for systems expressible as a polynomial system, many transcendental equations over bounded domains, and perhaps a few special cases. The first works becauseInverseFunction
works onInterpolatingFunction
, but it will return only one solution.NSolve
does not seem to handleParametricFunction
, though, if so, it should give an error meessage. To solve the last equation, useDSolve
instead ofParametricNDSolve
andSolve
instead ofNSolve
. $\endgroup$DSolve
can obtain, then you'll probably have to construct a numerical solution for $m=m(k)$. For example, solve at several points and interpolate. OrmFN[k_] := Module[{m}, m /. FindRoot[f[1, m, k] == 0, {m, 1}]]
. You might want to figure out a better starting point forFindRoot
than the1
in{m, 1}
. $\endgroup$