1
$\begingroup$

I wanna know which options do I have with a ParametricFunction, which i got from solving an ODE with ParametricNDSolve? Can I find for example the Minimum for this function, which dependes form the parameters and a fixed variables ?

My aim is to create a new function where ParametricFunction is involved. This new function should depend just from the parameters of the parametricfunction, so i can minimize the function with the parameters as "new" variables.

So as an quick example:

pfun = ParametricNDSolveValue[ {x''[t] + a x'[t] + b^2 x[t] == 0, 
   x[0] == 1, x'[0] == 0}, x, {t, 0, 10}, {a, b}]

The output is: ParametricFunction[ <> ] Whit Expression:x and Parameters:{a,b}.

What I want now is the Minimum of this Function, where i can fix x for example as x=1 and the Parameters {a,b} are my new variables. So for which a and b is the function minimized.strong text

So here for example, we have lots of local minima/maxima:

Plot[pfun[1, b][3], {b, -10, 0}]

Here the Plot:

enter image description here

$\endgroup$
3
  • $\begingroup$ Can you give an example, with code, of what you would like to accomplish? The parametric function will surely also depend on the independent variable in the original equation as well, and not just the parameters, wouldn't it? $\endgroup$
    – MarcoB
    Jan 26, 2022 at 15:19
  • $\begingroup$ It looks like this function does not have a minimum. E.g. Plot[pfun[a, 3][1], {a, -10, 0}] $\endgroup$ Jan 26, 2022 at 15:46
  • $\begingroup$ Yes, you are right i will define a new function with a picture, just a sec. $\endgroup$
    – hinata
    Jan 26, 2022 at 15:56

2 Answers 2

3
$\begingroup$

You can probe the parametric function to retrieve its properties:

pfun["Properties"]
(*{"Creator", "DependentVariables", "Expression", 
 "IndependentVariables", "Parameters", "Properties", "TooltipTable"}*)

Then, using the list the above returns, you can access the properties as following:

pfun["IndependentVariables"]
(*{t}*)
$\endgroup$
1
  • $\begingroup$ Thank you very much for this helfpul information, but is it possible to change the Properties ? I would like to get a function, where the Parameters {a,b} are defined as IndependetnVariables and t should transform to my parameter with a fixed value (for example t=1). $\endgroup$
    – hinata
    Jan 26, 2022 at 20:59
1
$\begingroup$
Clear["Global`*"]

pfun = ParametricNDSolveValue[
  {x''[t] + a x'[t] + b^2 x[t] == 0, x[0] == 1, 
    x'[0] == 0}, x, {t, 0, 10}, {a, b}];

For a == 1 and b == -5

The maxima

max = {t, pfun[1, -5][t]} /.
    FindRoot[D[pfun[1, -5][t], t] == 0, {t, #}] & /@
  {0, 1.4, 2.5, 3.9, 5.1, 6.4, 7.5, 8.7}

(* {{0., 1.}, {1.26297, 0.531802}, {2.52594, 0.282813}, {3.7889, 
  0.150401}, {5.05187, 0.0799835}, {6.31484, 0.0425354}, {7.57781, 
  0.0226204}, {8.84077, 0.0120296}} *)

The minima

min = {t, pfun[1, -5][t]} /.
    FindRoot[D[pfun[1, -5][t], t] == 0, {t, #}] & /@
  {0.6, 1.9, 3.2, 4.4, 5.7, 6.9, 8.2, 9.5}

(* {{0.631484, -0.729248}, {1.89445, -0.387815}, {3.15742, -0.206241}, {4.42039, \
-0.109679}, {5.68335, -0.0583277}, {6.94632, -0.0310188}, {8.20929, \
-0.0164959}, {9.47226, -0.00877254}} *)

Plotting,

Legended[
 Plot[pfun[1, -5][t], {t, 0, 10},
  PlotStyle -> ColorData[97][2],
  AxesLabel -> (Style[#, 14] & /@ {t, HoldForm[pfun]}),
  Epilog -> {AbsolutePointSize[4],
    Blue, Tooltip[Point[#], #] & /@ min,
    Red, Tooltip[Point[#], #] & /@ max},
  PlotRange -> All],
 Placed[
  PointLegend[{Red, Blue}, {"max", "min"}],
  {.5, .7}]]

enter image description here

For a == 1 and t == 3

The maxima are

maxb = {b, pfun[1, b][3]} /.
    FindRoot[D[pfun[1, b][3], b] == 0, {b, #}] & /@
  {-8.4, -6.4, -4.2, -2.2, 0}

(* {{-8.41223, 0.223525}, {-6.32922, 0.22383}, {-4.25714, 0.224685}, {-2.22439, 
  0.228984}, {0., 1.}} *)

The minima are

minb = {b, pfun[1, b][3]} /.
    FindRoot[D[pfun[1, b][3], b] == 0, {b, #}] & /@
  {-9.5, -7.4, -5.3, -3.2, -1.3}

(* {{-9.45561, -0.223443}, {-7.36993, -0.223645}, {-5.29103, -0.224133}, \
{-3.23147, -0.225849}, {-1.2711, -0.242501}} *)

Plotting,

Legended[
 Plot[pfun[1, b][3], {b, -10, 0},
  PlotStyle -> ColorData[97][2],
  AxesLabel -> (Style[#, 14] & /@ {b, HoldForm[pfun]}),
  Epilog -> {AbsolutePointSize[4],
    Blue, Tooltip[Point[#], #] & /@ minb,
    Red, Tooltip[Point[#], #] & /@ maxb}],
 Placed[
  PointLegend[{Red, Blue}, {"max", "min"}],
  {.5, .7}]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank u for ur help! $\endgroup$
    – hinata
    Jan 27, 2022 at 8:55

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.