Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168693
Image: ubuntu2004
#simple example of Euler's Method var('t','y') f(t,y) = y start = 0.0 end = 1.0 solution(t) = float(e)^t numOfIterations = 10 h = (end-start)/numOfIterations y00 = 1.0 #initial value t00 = start; soln = [[t00,y00]] for i in range(numOfIterations): y00 = y00+h*f(t00,y00) t00=t00+h soln.append([t00,y00]) print "%10r %20r %20r"%(t00,y00,solution(t00))
0.100000000000000 1.10000000000000 1.10517091807565 0.200000000000000 1.21000000000000 1.22140275816017 0.300000000000000 1.33100000000000 1.34985880757600 0.400000000000000 1.46410000000000 1.49182469764127 0.500000000000000 1.61051000000000 1.64872127070013 0.600000000000000 1.77156100000000 1.82211880039051 0.700000000000000 1.94871710000000 2.01375270747048 0.800000000000000 2.14358881000000 2.22554092849247 0.900000000000000 2.35794769100000 2.45960311115695 1.00000000000000 2.59374246010000 2.71828182845904
eulers_method?
2.7182818284590451