2.6 Numerics

2.6 What/Why/How

What: Gives a numerical approximation to an IVP

Why: Most IVPs do not have analytical solutions

How: Lots of arithmetic

Euler's Method

y'[x]=f[x,y[x]]

((y[x+h]-y[x])/h) ≈ f[x,y[x]]

(Subscript[x, n+1])=(Subscript[x, n])+h
(Subscript[y, n+1])=(Subscript[y, n])+h f[(Subscript[x, n]),(Subscript[y, n])]

Code

f[x_,y_]:=Sin[ArcTan[x + Cos[(y^2)]] (x+y)]/Log[(x^2)+2]
{x0,y0}={15.0,-1};
h=0.1;
{x,y}={x0,y0};
DotPic=ListPlot[
Table[
{x,y} ={ x+ h,y+ h*f[x,y]},
{100}],
PlotStyle->Red
]

NDSolve

Clear[x,y]
ySol[x_]=y[x]/.NDSolve[{
y'[x]==f[x,y[x]],
y[x0]==y0
},
y[x],
{x, 0,20}
][[1]];
Show[
Plot[ySol[x],{x,0,20}],
DotPic]