Reminders

2.1 Pretty direction fields

f[x_,y_]:= x Sin[x y]
StreamPlot[{1,f[x,y]}, {x,-3,3},{y,-3,3}]

2.2 Separable Equations

Just like in Calc an ODE of the form
	dy/dx = g[x]h[y]
is separable.  You get the general solution by separating variables and integrating
	∫1/h[y]dy = ∫g[x]dx+C.

2.3 Linear 1st Order ODE

Standard form
	y'[x]+P[x]y[x]=f[x]
Compute μ[x]=(e^(∫P[x]dx)) and multiply eq by μ and collapse product rule terms and integrate to get general solution
	({{μ[x]y'[x], +, μ[x]P[x]y[x], =, μ[x]f[x]}, {μ[x]y'[x], +, μ'[x]y[x], =, μ[x]f[x]}, { ,  , (μ[x] y[x])', =, μ[x] f[x]}, { ,  , μ[x]y[x], =, ∫μ[x]f[x]dx+C}})
As always if I have an initial condition I plug it into the general solution.

2.4: Exact

The equation  M dx + N dy =0 is exact if ((∂M)/(∂y))=((∂n)/(∂x)) and the solution is f[x,y]=c where 
 M=((∂f)/(∂x)) and N=((∂f)/(∂y)).  
First integrate f=∫((∂f)/(∂x))dx+g[y]=∫M[x,y]dx+g[y] 
then find g'[y] by differentiating 
((∂f)/(∂y))=N=(∂/(∂y))((∂/∂)∫M[x,y]dx )+g'[y]
finally integrate to get g and write down the general solution f[x,y]=c.
As always if you have an IC you plug into the general solution.

Numerics

The % of ODEs that have analytical answers is tiny.

Same as the % of functions with analytical integrals.

All IVPs can be solved numerically.

All definate integrals can be approximated numerically.

Left Hand Sum, Trapezoid Rule, Simpson’s Rule, …, NIntegrate

We are going to learn the LHS for ODEs.

It is called Euler’s Method

We are going to learn how to use NDSolve

NDSolve

NDSolve is easy

f[x_,y_]:=Sin[Sin[x] + y]+ Cos[x]
{x0,y0}={1,2};
ySol=y/.NDSolve[ {
y'[x]==f[x,y[x]],
y[x0]==y0
},
y,
{x,x0,6}][[1]]

ySol[1.2]
Plot[ySol[x],{x, 1, 6}]

It works in much more generality.

Clear[ySol]
ySol[t_]={y1[t],y2[t],y3[t]}/.NDSolve[ {
y1''[t]+y1[t]== Sin[t y2[t]+ y3[t]],
y2'[t]== Sin[t y1[t]+ y3[t]],
y3'[t]==Cos[0.1 t + ArcTan[ y1'[t]+y2[t]]],
y1[0]==2,
y2[0]==3,
y3[0]==4,
y1'[0]==5
},
{y1,y2,y3},
{t,0,123}][[1]]
Plot[ySol[t],{t,0,123}]

Euler

All we do to understand Euler is look at the plainest most boring direction filed we can get out hands on and think about joining up the dashes with sloped bits of line all of the same horizontal length.  You start at {x0,y0} and keep going till you get bored.  You need to decide how big your steps are going to be.  The text calls the step size h.  So will we.

f[x_,y_]:=Sin[x y]+ Cos[x]
{x0,y0}={1,2};
VectorPlot[ {1,f[x,y]},
{x,0,6},
{y,0,3},
VectorPoints->{21,21},
GridLines->Automatic,
Prolog->{Red,PointSize[0.02], Point[{x0,y0}]},
VectorScale->{Tiny,Tiny, None}]

The first tangent line goes through {(Subscript[x, 0]),(Subscript[y, 0])} with slope f[(Subscript[x, 0]),(Subscript[y, 0])].  The formula is
	y[x]≈TanLine[x]=(Subscript[y, 0])+f[(Subscript[x, 0]),(Subscript[y, 0])](x-(Subscript[x, 0]))
we pick a smallish step size h and get 
	y[(Subscript[x, 0])+h]≈TanLine[(Subscript[x, 0])+h]=(Subscript[y, 0])+f[(Subscript[x, 0]),(Subscript[y, 0])]h
We define (Subscript[x, 1])=(Subscript[x, 0])+(1)h  and 
	(Subscript[y, 1])=(Subscript[y, 0])+h f[(Subscript[x, 0]),(Subscript[y, 0])]
and hopefully y[(Subscript[x, 0])+h]≈(Subscript[y, 1]).   Repeating this process
	({{(Subscript[x, n]), =, (Subscript[x, 0])+n h}, {(Subscript[y, n]), =, (Subscript[y, n-1])+f[(Subscript[x, n-1]),(Subscript[y, n-1])]h}})
gives you a set of points that approximate the solution to the ODE.

Smaller stepsize h means you need more steps to get to the same place.

f[x_,y_]:=Sin[x y]+ Cos[x]
{x0,y0}={1,2};
{h, Steps}={0.1,50};
{x,y}={x0,y0};
Euler=Table[
{x,y}={x,y}+h{1,f[x,y]},
{Steps}
];
VectorPlot[ {1,f[x,y]},
{x,0,6},
{y,0,3},
VectorPoints->{21,21},
GridLines->Automatic,
Prolog->{Red,PointSize[0.02], Point[{x0,y0}]},
Epilog->{Red, Line[Euler],Black,Point[Euler]},
VectorScale->{Tiny,Tiny, None}]

TableForm[Euler,
TableHeadings->{Automatic,{"x","y"}}]