# Plotting solutions to ODE for continuously varying parameters

I am trying to plot the solution of an ODE with continuously varying one of its three parameters. (I just fixed two of them for simplicity.) Any suggestions?

ω = 1;
ϵ = 0.001;

eqn = y''[r] + (4 r^3)/(r^4 - T^4) y'[r] + ( ω^2 r^4)/(r^4 - T^4)^2 y[r] == 0;

Manipulate[
fn = ParametricNDSolveValue[{eqn,
y'[T + ϵ] == -((ω (I T^2 + (T + ϵ) ω))/(ϵ (T + ϵ) (2 T + ϵ) (T + ϵ - I ω))) y[T + ϵ],
y[2] == 1},
y, {r, T + ϵ, 2}, {T}];
p = Plot[Re[fn[T]], {r, T + ϵ, 2}];
Show[p], {T, 0.1, 1}]

• The actual problem is variable-boundary condition y'[T + ϵ] == ... Perhaps, ParametricNDSolveValue don't understand it. – ybeltukov Jan 20 '15 at 23:29
• @ybeltukov, you may well be correct. I spent sometime trying to make ParametricNDSolveValue work but always received an error message associated with the y'[T + ϵ] boundary condition. – bbgodfrey Jan 20 '15 at 23:40

The code in the Question can be recast as

ω = 1; ϵ = 0.001;
Manipulate[fn = With[{T = t}, NDSolveValue[{y''[r] + (4 r^3)/(r^4 - T^4) y'[r] +
(ω^2 r^4)/(r^4 - T^4)^2 y[r] == 0, y'[T + ϵ] == -((ω (I T^2 + (T + ϵ) ω))/
(ϵ (T + ϵ) (2 T + ϵ) (T + ϵ - I ω))) y[T + ϵ], y[2] == 1}, y, {r, T + ϵ, 2}]];
Plot[Re[fn[r]], {r, t + ϵ, 2}, PlotRange -> All], {t, 0.1, 1}]


which produces the desired Manipulate output. The curve for t=.35 is

• Thanks a lot @bbgodfrey! – pinaki Jan 20 '15 at 23:34
• You are welcome. Note that I made a minor change to Plot in the Answer a few minutes ago. – bbgodfrey Jan 20 '15 at 23:41

ParametricNDSolve is a perfectly good way to go about this, so I'll leave that for another answerer. Instead, for fun I'll show an equivalent trick to plot an ODE with respect to one of its parameters by augmenting the system into a 2D PDE.

As an example, consider the oscillator equation,

$$f''(x)=-\omega^2f(x)$$

where $\omega$ is to vary over a range of values. You could just solve the ODE a bunch of times and plot the results together using Manipulate, or you could augment the system into the following PDE:

$$f^{(2,0)}(x,y)=-\omega^2(y)f(x,y)$$

where $\omega^2(y)$ takes on the values of whatever range you want to plot the parameter over. The resulting solution $f(x,y)$ then becomes a plot of the parameter-varied ODE.

As an explicit example:

DSolveValue[
Derivative[2, 0][f][x, y] == -y^2 f[x, y] && f[0, y] == 1 &&
Derivative[1, 0][f][0, y] == 1, f[x, y], {x, y}]
DensityPlot[%, {x, 0, 7}, {y, 0, 4}, PlotPoints -> 50,
ColorFunction -> "TemperatureMap", PlotRange -> 2 {-1, 1}]


producing

$$\frac{\sin (x y)+y \cos (x y)}{y}$$

I'll leave it to you to adapt your ODE to this method :)