I am solving a system consisted of 3 ODEs using ParametricNDSolveValue
. Everytime when I want to obtain each solution at certain parameters, I would use:
solutions = ParametricNDSolveValue[{ODEs}, {a, b, phi}, {x, 0, 1}, {TM, miumaxA, miumaxB}];
asol[x_]=solutions[para1val,para2val,para3val][[1]][x];
bsol[x_]=solutions[para1val,para2val,para3val][[2]][x];
phisol[x_]=solutions[para1val,para2val,para3val][[3]][x];
However, this might waste computational resource, as the solution is computed 3 times, in each line. Then, I try :
{asol,bsol,phisol}=solutions[para1val,para2val,para3val][x];
However, this does not work. solutions[para1val,para2val,para3val][x]
would give a list of three interpolating functions. Is there any way to extract interpolating function of each solution once solutions[para1val,para2val,para3val][x]
is evaluated?
[x]
and write{asol,bsol,phisol} = solutions[para1val,para2val,para3val]
instead, does that do it? For example, try evaluatingasol[0.5]
afterwards. $\endgroup$asol[x_]:=solutions...
instead ofasol[x_]=solutions...
. You may also definesol[x_, n_Integer]:=solutions[para1val,para2val,para3val][[n]][x]
, which yields you the solution definition for all valuesn=1,2,3
. In principle, this makes what you want: the function definition persisting through the whole Mma session. $\endgroup$[x]
, I am able to getasol[x]
,bsol[x]
, andphisol[x]
as separated interpolating function. Your help is very much appreciated. @AlexeiBoulbitch By changing to:=
, I would get error message "dSetDelayed::shape". $\endgroup$ParametricNDSolveValue
caches results by default, so the ODEs won't be repeatedly solved and re-solved. It was designed with your sort of use-case in mind. $\endgroup$