1

enter image description here

I am generally confused on how to solve this problem, I was given very little background on how to solve an initial value problem through Mathematica.

I believe I have created the graph below properly, correct me if I am wrong.

enter image description here

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Mike
  • 35
  • 1
  • 8

2 Answers2

2

Okay so first, you did a relative good job if this is your first time with Mathematica/Programming.

You used DSolve to get the Solution which is good and right. But I would say, you take a look at DSolveValue. Its the same Function, its just putting out the solution with nothing else (No list, no Rule) which is what you want here.

If you still want to use DSolve, you have to substitute the y[x] with a ReplaceAll and a Part to get rid of the List. This looks like this:

sol = (y[x] /. DSolve[{y'[x] == x^2*y[x], y[1] == 3}, y[x], x])[[1]]

3 E^(-(1/3) + x^3/3)

(You dont need the Part (...[1]) here since Plot could handle it)

Second you used VectorPlot. But for the Phase-Portrait i'd recommend StreamPlot.

You can now Plot your Field, Plot your solution (with a simple Plot) and combine these two with Show.

This looks like this:

sol = DSolveValue[{y'[x] == x^2*y[x], y[1] == 3}, y[x], x]

Show[StreamPlot[{1, x^2*y}, {x, -4, 4}, {y, -8, 8}], 
Plot[sol, {x, -4, 4}, PlotStyle -> Red]]

Fieldplot

(I also added a PlotStlye->Red to the Plot to get a good contrast between the field plot and ODE-Plot)

Hope this helps

Julien Kluge
  • 5,335
  • 1
  • 17
  • 29
  • This is very helpful, thank you so much – Mike Jul 19 '17 at 20:24
  • I am reading the instructions where it says my name for the each function. So should it look like this: sol=Mike[x_]=y[x] /. DSolve[{y'[x] == x^2 y[x], y[1] == 3}, y[x], x][[1]]? I found that this code prints an output that seems correct I just don't know what function they want me to name. Thanks – Mike Jul 19 '17 at 21:09
2

It can done by utilizing the StreanPoints option, which takes the initial condition as an input and select the streamline passing through the initial condition,

f[x_, y_] := x^2*y

StreamPlot[{1, f[x, y]}, {x, -5, 6}, {y, -4, 3}, Frame -> False, 
 Axes -> True, AspectRatio -> 1/GoldenRatio, AxesLabel -> {"x", "y(x)"}, BaseStyle -> 12, 
 StreamPoints -> {{{{1, 3}, Red}, Automatic}}]

enter image description here

zhk
  • 11,939
  • 1
  • 22
  • 38