Message Boards Message Boards

2 Replies
1 Total Likes
View groups...
Share this post:

Using the output on ParametricNDSolve in a Piecewise function

Hi folks - this is my first post here so I hope I'm putting question in the right place! I'm using ParametricNDSolve to evaluate a function (Eb1r,t]) with four free parameters and two dependent variables between two boundaries rn and ro. However, the function also needs to be defined between 0 and rn - in this case it's just a constant that takes on the values at the boundary rn, given by Eb1[rn,t]. I've outlined the problem on [Stack Exchange here , and in essence I'm unable to use the output of ParametricNDSolve in the same way I'd use output of NDsolve; for example, I try to feed it into piecewise like this;

(*Parametric solution for unknowns kme, kmn, j and eo, for functions Ef1 and Eb1*)

x = ParametricNDSolve[{eqnBo == 0, Eb1[r, 0] == 0, eqnDe == 0,  Ef1[r, 0] == 0, Derivative[1, 0][Ef1][rn, t] == 0,  Ef1[ro, t] == eo},  Eb1, {r, rn, ro}, {t, 0, 14400}, {kme, kmn, j, eo}];

which works fine, but my attempts to manipulate output fail miserablely - for example, when I try to define a piecewise function at t = 14400 -

Ebound[r_] =  Piecewise[{{Eb1[rn, 14400] /. x, r < rn}, {Eb1[r, 14400] /. x, r >= rn}}];

I keep getting the error ParametricNDSolve::fpct: "Too many parameters in {kme,kmn,j,eo} to be filled from {r,14400}."

I can't work out if this is just some syntax error, or whether there is a deeper reason why I cannot manipulate the parametric equation. Does anyone have any ideas whether this is possible, or what I'm doing wrong? Thanks! A MWE of the problem is appended to this post for anyone who might be interested.

2 Replies

ParametricNDSolve is basically the setup part of NDSolve, for use when you want to numerically solve similar differential equations multiple times and they only differ in terms of certain parameters. To get a solution from it, you have to specify the values of the parameters, as NDSolve is a numerical algorithm. It's not like DSolve, which can keep parameters as symbols. You're not providing the values of the parameters.

POSTED BY: Frank Kampas

Thanks - that's a pain! I was hoping to use nonlinearmodelfit for the parameters {kme,kmn,j,eo} between known limits. The fact that the function is different before and after the boundary rn is complicating my attempts to do so, which is why I was trying to use Piecewise. Is there a clever way around this issue?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract