Y by Adventure10, Mango247
After reading the section in AoPS Calculus on Euler's Method, I was experimenting with a little python script to calculate
with this method (as the book recommended), but I also tried varying the number of steps used.
If you run the code, you get the results from applying euler's method to calculate
with
,
,
, etc. steps.
But there appears to be a pattern in the errors. To see this pattern, here are a couple more rows of the output:
After
steps, the error seems to decrease by almost exactly a factor of
when the number of steps is increased by a factor of
. Can anyone give an explanation for this seemingly inversely proportional behavior?

import sys import math def diff_exp(x, y): '''A function representing a differential equation. This function represents y' = diff_equation(x, y), which is the differential equation for e^x. ''' return y def euler(start, val, target, equation, steps): increment = (target - start) / steps for step in range(steps): val = val + increment * equation(start, val) start += increment return val def main(): print("Steps|Absolute Error") print("-----|--------------") amt = 1 for i in range(6): error = abs(euler(0, 1, 0.3, diff_exp, amt) - math.exp(0.3)) print("10^%02d|%.12f" % (i, error)) amt *= 10 if __name__ == '__main__': status = main() # sys.exit(status) # doesn't work on pywindow
If you run the code, you get the results from applying euler's method to calculate




But there appears to be a pattern in the errors. To see this pattern, here are a couple more rows of the output:
Steps|Absolute Error
-----|--------------
10^00|0.049858807576
10^01|0.005942428232
10^02|0.000606088209
10^03|0.000060730134
10^04|0.000006074229
10^05|0.000000607435
10^06|0.000000060744
10^07|0.000000006074
After



This post has been edited 1 time. Last edited by fz0718, Jul 23, 2015, 4:46 PM