1
$\begingroup$

I am new to Mathematica, so excuse me if this is trivial. I could not find anything similar by browsing questions or the wiki.

I am working with a long set of ODEs but currently my problem can be watered down with the following example:

sol = ParametricNDSolve[{f'[t] == (a+b)*f[t], f[0] == 1}, f, {t, 0, 10}, {a,b}]

Table[NSolve[Evaluate[{f[b][a][5]==0}/.sol],a],{b,2,4,0.5}]

What I am trying to accomplish with this is to calculate the value of a that yields f[b][a][5]==0 for every b in the range {b,2,4,0.5}. However, I am getting the following error:

ParametricNDSolve::fpct: Too many parameters in {a,b} to be filled from {2}.

Thanks for taking the time to read, any help would be appreciated!

EDIT: As @Daniel Huber noticed I had the syntax for the two-parametric function wrong. With the corrected syntax,:

sol = ParametricNDSolve[{f'[t] == (a+b)*f[t], f[0] == 1}, f, {t, 0, 10}, {a,b}]
    
    Table[NSolve[Evaluate[{f[b,a][5]==0}/.sol],a],{b,2,4,0.5}]

I no longer get the aforementioned error. Yet the output is blank {{}, {}, {}, {}, {}}.

$\endgroup$
2
  • $\begingroup$ The 2 parametric function f needs 2 arguments, e.g. like f[2,1] and not f[2][1] $\endgroup$ Nov 10, 2022 at 20:09
  • $\begingroup$ Thanks for pointing this out. When I modify the code to f[b,a] I no longer get the error. However, I don't get any results either. Instead, the output is {{}, {}, {}, {}, {}} $\endgroup$ Nov 10, 2022 at 20:15

1 Answer 1

1
$\begingroup$

I would play around with the function that you get first before trying to just use numerical root finding on the function. For instance, a little playing around got me this:

sol = ParametricNDSolve[{f'[t] == (a + b)*f[t], f[0] == 1}, f, {t, 0, 10}, {a, b}];
ContourPlot[0 == f[b, a][5] /. sol // Evaluate, {a, -12, -10}, {b, 2, 4}]

enter image description here

From there, we can use FindRoot along with some reasonable guesses for the value of a based on the intersection of those grid lines with the zero-contours of the function:

guesses = {-10.25, -11.75, -11.25, -12.75, -13, 25};
bs = Range[2, 4, 0.5];
Table[FindRoot[f[bs[[kk]], a][5] /. sol, {a, guesses[[kk]]}], {kk, 1, Length@bs}]
(* {{a -> -12.5729}, {a -> -15.1251}, {a -> -13.5729}, {a -> -16.1251}, {a -> -13.8383}} *)

Not perfect, but if give you the idea.

$\endgroup$
1
  • $\begingroup$ This worked, but unfortunately my system of DEs showed a very strange behavior with ParametricNDSolve with two parameters. I will probably post a more complete question with my full code. Thanks for taking the time to help! $\endgroup$ Nov 11, 2022 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.