5
$\begingroup$

I am supposed to create a detailed slope-field for x' = x + t/2

I have made a slope field using:

f[t_, x_] = x + t/2
fld = VectorPlot[{1, f[t, x]}, {t, -3, 3}, {x, -3, 3}]

I need to make three solution curves on the slope field, but I cannot figure out how to do that

$\endgroup$
1
  • $\begingroup$ One possible approach is to make a separate plot of the solutions and then use Show[ ] to combine the slope field plot with the solution plot. $\endgroup$
    – LouisB
    Feb 17, 2020 at 22:03

2 Answers 2

9
$\begingroup$

The option StreamPoints works also with VectorPlot, so you could do something like

f[t_, x_] = x + t/2
fld = VectorPlot[{1, f[t, x]}, {t, -3, 3}, {x, -3, 3}, 
  StreamPoints -> {{{{1, .5}, Red}, Automatic}}]

Mathematica graphics

Where (1,.5) above can be specific initial condition. You can more lines as needed.

fld = VectorPlot[{1, f[t, x]}, {t, -3, 3}, {x, -3, 3},
  StreamPoints -> {
    {{{-1, .5}, {Thick, Red}}, {{1, -.5}, {Thick, Blue}}, Automatic}
    }
  ]

Mathematica graphics

$\endgroup$
6
$\begingroup$

First find solution curves based on the dynamics:

ClearAll[x,dynamics,solutionCurve];
dynamics=x'[t]==x[t]+t/2;

(* based on constant *)
solutionCurve[c_]=x[t]/.First@DSolve[dynamics,x[t],t]/.C[1]->c

(* based on explicit point *)
solutionCurve[{τ_,ξ_}]=x[t]/.First@DSolve[{dynamics,x[τ]==ξ},x[t],t]

Now you can get the required plot with three solution curves by either changing the value of the constant or giving explicit points as follows:

Show[
    VectorPlot[
        {1,Last[dynamics]},{t,-3,3},{x[t],-3,3},
        FrameLabel->{t,x[t]}
    ],
    Plot[
        solutionCurve/@{-1,{0,-(1/2)},1},
        {t,-3,3},
        PlotStyle->{Red,Dashed}
    ]
]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.