# Plotting issue for nonlinear de

The following code with varying scaling parameter gives same plot. plz suggest correction.

Clear[x];

r=1;
eqn=x'[t]-1-r*x[t]-x[t]^2==0;
sol=x/.DSolve[{eqn,x[0]==0},x,t][[1,1]];
ParametricPlot[Evaluate[{sol[t],D[sol[t],t]}],{t,0,100}]

r=2;
eqn=x'[t]-1-r*x[t]-x[t]^2==0;
ParametricPlot[Evaluate[{sol[t],D[sol[t],t]}],{t,0,100}]

r=-2;
eqn=x'[t]-1-r*x[t]-x[t]^2==0;
ParametricPlot[Evaluate[{sol[t],D[sol[t],t]}],{t,0,100}]

r=0;
eqn=x'[t]-1-r*x[t]-x[t]^2==0;
ParametricPlot[Evaluate[{sol[t],D[sol[t],t]}],{t,0,100}]


Regards,

• The value of "r" has been changed several times.....maybe Clear[r] for each run? Commented Oct 12, 2015 at 3:15
• If your version of Mathematica supports this form of Table then: Clear[x, r]; Table[eqn = x'[t]-1-r*x[t]-x[t]^2==0; sol=x/.DSolve[{eqn, x[0]==0},x,t][[1,1]]; ParametricPlot[ Evaluate[{sol[t], D[sol[t], t]}], {t,0,100}], {r,{1,2,-2,0}}]
– Bill
Commented Oct 12, 2015 at 3:33
• Because you set r before the DSolve, you have to run DSolve again every time you reset r. Alternatively, don't set r ever and instead replace r with the new value using /. for each ParametricPlot. Commented Oct 12, 2015 at 3:34

marsh already has explained in a comment why the curves as generated by the code in the question look the same. Here we offer some alternative approaches.

eqn = x'[t] - 1 - r*x[t] - x[t]^2 == 0;
sol = x /. DSolve[{eqn, x[0] == 0}, x, t][[1, 1]];


provides the solution for all r in the range (-2, 2). Plotting the four cases in the question on a single curve shows that they differ. (Note the use of Limit to accommodate r -> 2, -2.)

ParametricPlot[Evaluate[Table[Limit[{sol[t], D[sol[t], t]}, r -> i], {i, {1, 2, -2, 0}}]],
{t, 0, 100}, AspectRatio -> 1, PlotRange -> {{-5, 5}, {0, 35}}, PlotPoints -> 1000]


Gaps in two of the curves can be filled by using negative as well as positive values for t.

However, it also is straightforward to obtain D[sol[t], t] as a function of sol[t].

FullSimplify[D[sol[t], t] /. Solve[x == sol[t], t][[1, 1]], C[1] ∈ Integers]
(* 1 + x (r + x) *)


In other words, the curves all are simple parabolas.

Plot[Evaluate[Table[%, {r, {1, 2, -2, 0}}]], {x, -5, 5}, AspectRatio -> 1]


Here, there are no gaps, of course.

I have deliberately confined this post to $t\in (0,1)$ to avoid stiffness issue (as discussed in related question).

f[x_, r_] := 1 + r x + x^2
Manipulate[
With[{sol =
ParametricNDSolve[{x'[t] == f[x[t], s], x[0] == 0}, {x, x'}, {t,
0, 0.9}, {s}]},
Column[{
Show[Plot[f[x, r], {x, -3, 3}, Frame -> True,
PlotRange -> {0, 10}],
ParametricPlot[Evaluate[{x[r][t], x'[r][t]} /. sol], {t, 0, 1},
PlotStyle -> {Red, Thick, Dashed}, Frame -> True,
PlotRange -> {0, 10}], FrameLabel -> {"x(t)", "x'(t}"}],
Show[StreamPlot[{1, f[x, r]}, {t, 0, 0.9}, {x, -3, 3}],
Plot[Evaluate[x[r][t] /. sol], {t, 0, 0.9},
PlotStyle -> {Red, Thick}], FrameLabel -> {"t", "x(t}"}]
}]], {r, -2, 2}]


Noting:

• x' v x can be plotted just by definition (see top plot)
• use of ParametricNDSolve