The goal is to draw the solution of $y'(t)=y(t)^2-t,\ y(0)=3$, over the region $\{(t,y): -2\le t\le 10,\ -4\le y\le 4\}$. I've started with:
Clear[f, t]
f[t_, y_] := y^2 - t
vp = VectorPlot[{1, f[t, y]}, {t, -2, 10}, {y, -4, 4},
VectorScale -> {0.03, 0.03, None},
Frame -> False, Axes -> True, AxesLabel -> {"t", "y"}]
Which gives this image:
Then I tried:
sol = DSolveValue[{y'[t] == y[t]^2 - t, y[0] == 3}, y, t]
Which gives a weird complex solution. I tried adding it to my direction field.
Show[vp, Plot[sol[t], {t, -2, 10}]]
Which gives this image:
Notice that it does not satisfy the initial condition $y(0)=3$. Then I tried:
Show[vp, Plot[Re[sol[t]], {t, -2, 10}]]
Which produces this image:
Again, it does not satisfy the initial condition $y(0)=3$. What am I doing wrong? Am I making some type of mistake?
Update: I've managed to find an old discussion How should I deal with messages being produced by my Manipulate? which provides some help.
Clear[f, t]
f[t_, y_] := y^2 - t
vp = VectorPlot[{1, f[t, y]}, {t, -2, 10}, {y, -4, 4},
VectorScale -> {0.03, 0.03, None}, Frame -> False, Axes -> True,
AxesLabel -> {"t", "y"}];
sol = NDSolveValue[{y'[t] == y[t]^2 - t, y[0] == 3,
WhenEvent[Abs[y[t]] > 4, "StopIntegration"]}, y, {t, -2, 2},
"ExtrapolationHandler" -> {Indeterminate &,
"WarningMessage" -> False}];
Show[vp, Plot[sol[t], {t, -2, 10}]]
Which produces this image.
Which is correct. Also, note that
sol[0]
produces the answer 3.
I was also able to do this:
tbl = Table[
NDSolveValue[{y'[t] == y[t]^2 - t, y[0] == b,
WhenEvent[Abs[y[t]] > 4, "StopIntegration"]}, y[t], {t, -2, 10},
Method -> "StiffnessSwitching",
"ExtrapolationHandler" -> {Indeterminate &,
"WarningMessage" -> False}], {b, -3, 3}];
Show[vp, Plot[tbl, {t, -2, 10}]]
Which produced this image.
However, a good question to still ask is about the ExtrapolationHandler. Could not find it in the documentation. Is it something that will continue to exist?






ExtrapolationHandler, have you tried searching the site?? – Michael E2 Jan 24 '17 at 18:14"ExtrapolationHandler"seems to have nothing to do with the original question. Whether or not it might be closed as a duplicate, it probably is more viable as a separate question, as discussed on meta here and here. – Michael E2 Jan 24 '17 at 22:42