Euler's Solution

Author: Gautam Dasgupta

June 17, 2000

Development

Clear[f];
f[x_, y_] := x* Sin[y]

y  =  y0  +  (x -  x0) * f[x0,  y0]

Clear[myEuler];
myEuler[f_, {x0_,  y0_},  
        x_] := 
y0  +  (x -  x0) * 
          f[x0,  y0]

test-1

myEuler[f, {x0,  y0},  x]

test-2

Clear[myEuler1];

myEuler1[f_,  h_,  {x0_, y0_}] := {x0 + h,  
        y0 + h*f[x0, y0]}

myEuler1[f, 0.1, {1,  1}]

test-3

f[x_,  y_] := x*Sin[y]

Clear[myEuler2];

myEuler2[{
f_,  
          h_,  {x0_, y0_}
}] := {f, 
        h, {x0 + h,  y0 + h*f[x0, y0]}
}

myEuler2[{f, 0.1, {1,  1}}]

myEuler2[{f, 0.1, {1.1`, 1.0841470984807897`}}]

test-4

f[x_,  y_] := x*Sin[y];
h =  .1;

Clear[
      myEuler3]; myEuler3[{x0_, y0_}]:={x0 + h,  
        y0 + h*f[x0, y0]}

myEuler3[{1,  1}]

myEuler3[{1.1`, 1.0841470984807897`}]

myEuler3[
myEuler3[{1,  
          1}]
]

myEuler3[
      myEuler3[
myEuler3[{1,  
            1}]
]]

Nest[myEuler3, {1,  1}, 3]

result = NestList[myEuler3, {1,  1}, 300];

ListPlot[result,  PlotJoined -> True]

test-5

f[x_,  y_] := x^2*Sin[x*y];
h =  .1;

Clear[myEuler3]; 
    myEuler3[{x0_, y0_}] := {x0 + h,  
        y0 + h*f[x0, y0]}
result = 
        NestList[myEuler3, {1,  1}, 300];
ListPlot[result,  PlotJoined -> True]