>> x_0 = 1; >> x_final = 3; >> y_0 = 2; >> help taylor_2 the program takes the initial data y_0 at the initial time x_0 and computes up to time x_final using timesteps of size dx. It creates two vectors, x and y, which you can then plot against each other plot(x,y) [x,y] = taylor_2(y_0,x_0,x_final,dx) >> [x,y] = taylor_2(y_0,x_0,x_final,.1); >> size(x) ans = 1 21 check that we've got the right final time: >> x(21) ans = 3 check that we've got the right initial time: >> x_0 x_0 = 1 save the solution at x=3 using h = .1 into the array a: >> a(1) = y(21); now compute with from x=1 to x=3 using h/2 = .1/2: >> [x,y] = taylor_2(y_0,x_0,x_final,.1/2); >> size(y) ans = 1 41 save the solution at x=3 using h = .1/2 into the array a: >> a(2) = y(41); now compute with from x=1 to x=3 using h/2 = .1/4: >> [x,y] = taylor_2(y_0,x_0,x_final,.1/4); save the solution at x=3 using h = .1/4 into the array a: >> a(3) = y(81); now compute with from x=1 to x=3 using h/2 = .1/8: >> [x,y] = taylor_2(y_0,x_0,x_final,.1/8); save the solution at x=3 using h = .1/8 into the array a: >> a(4) = y(161); look at the four approximations of y at x=3: >> a a = -0.3376 -0.3380 -0.3382 -0.3382 they look like they've converged up to 4 sig figs. >> format long >> a a = -0.33758054078694 -0.33804645710550 -0.33815005122311 -0.33817458729480 In fact, they're disagreeing at the 5th sig fig. Since we don't know the true solution, we can't look at the errors, but we can make ratios out of three approximations. We want these errors to get close to 4. >> rat1 = (a(1)-a(2))/(a(2)-a(3)) rat1 = 4.49751713070787 >> rat2 = (a(2)-a(3))/(a(3)-a(4)) rat2 = 4.22211505111064 The ratio's are close to 4, but not impressively so. Let's do some smaller time-steps. >> [x,y] = taylor_2(y_0,x_0,x_final,.1/16); >> size(x) ans = 1 321 >> a(5) = y(321); >> [x,y] = taylor_2(y_0,x_0,x_final,.1/32); >> size(x) ans = 1 641 >> a(6) = y(641); >> [x,y] = taylor_2(y_0,x_0,x_final,.1/64); >> size(x) ans = 1 1281 >> a(7) = y(1281); Now look at the approximate solutions. >> a a = Columns 1 through 4 -0.33758054078694 -0.33804645710550 -0.33815005122311 -0.33817458729480 Columns 5 through 7 -0.33818056416881 -0.33818203950381 -0.33818240602276 They've converged up to the 6th sig fig. Find the ratios: >> for i=1:5,rat(i) = (a(i)-a(i+1))/(a(i+1)-a(i+2)); end >> rat rat = Columns 1 through 4 4.49751713070787 4.22211505111064 4.10516796412455 4.05119785879381 Column 5 4.02526260515325 The ratios are decreasing apparently to 4. As we expect. Now, if we took h really really small then the subsequent differences would be at the level of round-off error and the ratios would go bad. So you would see them get close to 4 and then veer away. But for the h's we used, the smallest difference is: >> a(6)-a(7) ans = 3.665189449719719e-007 diary off