"); hg.document.close(); } function ptip(){ hg=window.open('','','toolbar=no,width=400,height=100,top=0,left=0'); hg.document.open(); hg.document.writeln(""); hg.document.writeln("Positive definite "); hg.document.close(); } function sclose(){ hg.window.close(); }  
Example 3:
Solve the differential equation y' = x/y, y(0)=1 by Euler's method to get y(1). Use the step lengths h = 0.1 and 0.2 and compare the results with the analytical solution (y2 = 1 + x2)

Solution:       f(x, y) = x/y,

with h = 0.1
y1 = y0 + h f(x0, y0) = 1.0 + 0.1*0.0/1.0 = 1.00
y2 = y1 + h f(x1, y1) = 1.0 + 0.1*0.1/1.0 = 1.01
y3 = y2 + h f(x2, y2) = 1.01 + 0.1*0.2/1.01 = 1.0298
y4 = y3 + h f(x3, y3) = 1.0298 + 0.1*0.3/1.0298 = 1.0589
y5 = y4 + h f(x4, y4) = 1.0589 + 0.1*0.4/1.0589 = 1.0967
y6 = y5 + h f(x5, y5) = 1.0967 + 0.1*0.5/1.0967 = 1.1423
y7 = y6 + h f(x6, y6) = 1.1423 + 0.1*0.6/1.1423 = 1.1948
y8 = y7 + h f(x7, y7) = 1.1948 + 0.1*0.7/1.1948 = 1.2534
y9 = y8 + h f(x8, y8) = 1.2534 + 0.1*0.8/1.2534 = 1.3172
y10 = y9 + h f(x9, y9) = 1.3172 + 0.1*0.9/1.3172 = 1.3855

with h = 0.2
y1 = y0 + h f(x0, y0) = 1.0 + 0.2*0.0/1.0 = 1.0
y2 = y1 + h f(x1, y1) = 1.0 + 0.2*0.2/1.0 = 1.0400
y3 = y2 + h f(x2, y2) = 1.0400 + 0.2*0.4/1.0400 = 1.1169
y4 = y3 + h f(x3, y3) = 1.1169 + 0.2*0.6/1.1169 = 1.2243
y5 = y4 + h f(x4, y4) = 1.2243 + 0.2*0.8/1.2243 = 1.3550

Comparison of numerical and analytical solutions:
 

x
Numerical Solution
h = 0.1          h = 0.2
Analytical solution
0.0
1.0
1.0
1.0
0.1
 1.0
 
 1.0050
0.2
 1.01
 1.0
1.0198
0.3
 1.0298
 
 1.0440
0.4
 1.0589
1.0400 
 1.0770
0.5
1.0967
 
 1.1180
0.6
  1.1423
 1.1169
 1.1662
0.7
 1.1948
 
 1.2207
0.8
 1.2534
 1.2243
 1.2806
0.9
1.3172 
 
 1.3454
1.0
 1.3855
 1.3550
 1.4142