# Make the initial condition of a differential equation a function. DSolve and ParametricNDSolve

I'm trying to do something with DSolve and after I want to translate the solution of the problem to "ParametricNDSolve", however I can't.

This is the problem, I have a function, and a differential equation that depends on this function

f[c_] := c+c^2;
DE = DSolve[{D[r[x]/(1 + x)^4, x] == 0, r[f[c]] == 1}, r[x], x];


With this code I get

r[x] -> (1 + x)^4/(1 + c+c^2)^4


So if a choose a particular $$c$$, I get a particular initial condition, for example $$c=1$$, then

r[x] -> (1 + x)^4/(3)^4


Now, if I choose for example $$x=0$$, I get $$r[0]=1/3^4$$. However I have to do this "manually", I can't find a way to do with code.

I try with ParametricNDSolve, for example

DEP = ParametricNDSolve[{D[r[x]/(1 + x)^4, x] == 0, r[ f[c]   ] == 0},r, {x, 0, 100}, {c}];


With $$f$$ defined as before. And after of this I try to evaluate the solution in a specific initial condition and in some specific point, for example $$c=1$$ and $$x=0$$ using

r[1][0]/.DEP


However this does not work, I know that ParametricNDSolve needs to have a predefined value of $$f[c]$$ in order to work, but I can't find a way fix this value.

I need to solve the problem with ParametricNDSolve because the differential equation that I'm working seems that doesn't have analytical solution.

I think I've seen this before. I do not think the Parameter, in ParametricNDSolve can be in the initial condition/Boundary condition but only in the ODE itself. That is why it does not work. You get the same exact error as if you did NDSolve[{D[r[x]/(1+x)^4,x]==0,r[f[c]]==1},r,{x,0,100}] with c not defined.

If you look at the examples in ParametricNDSolve all have the parameter inside the ODE, not in the initial conditions.

One away around this, is to use NDSolve but manually vary c each time you solve the ODE. Like this

ClearAll[f, c];
f[c_?NumericQ] := c + c^2;
Manipulate[

Module[{x, sol, r},
sol = NDSolve[{D[r[x]/(1 + x)^4, x] == 0, r[f[c]] == 1}, r, {x, 0, 100}];
Plot[Evaluate[r[x] /. sol], {x, 0, 100},
PlotRange -> {Automatic, {0, 300}},
GridLines -> Automatic, GridLinesStyle -> LightGray,
PlotStyle -> Red, PlotLabel -> "Solution for the ODE",
AxesLabel -> {"x", "r[x]"}, BaseStyle -> 12]
],

{{c, 1, "c"}, 1, 5, .1, Appearance -> "Labeled"},
TrackedSymbols :> {c}
]

• Thank you for suggesting the reading of another post. Jun 6 '20 at 3:52

I think that I found the answer combining a previous post with my problem.

To solve the problem I will use NDSolve. We take $$fg(c)$$ as a function of $$c$$.

fg[c_] := c + c^2;


Now we can define the differential equation

DEE[c_] := NDSolve[{D[r[x]/(1 + x)^4, x] == 0, r[fg[c]] == 1}, r, {x, -10, 10}];


And then we define another function

 yfun = First[r /. DEE[1]];


And this mean that I choose $$c$$ to be $$c=1$$.

Then you can evaluate in $$x=0$$

yfun[0]


Such that $$yfun[0]=0.0123456$$ and this value is equal to $$1/3^4$$, so the problem is solved.