Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168695
Image: ubuntu2004
#simple Runga-Kutta Order 4 var('t','y') f(t,y) = y start = 0.0 end = 1.0 solution(t) = float(e)^t numOfIterations = 2 h = (end-start)/numOfIterations y00 = 1.0 #initial value t00 = start; soln = [[t00,y00]] for i in range(numOfIterations): s1 = f(t00,y00) s2 = f(t00+h/2,y00+h/2*s1) s3 = f(t00+h/2,y00+h/2*s2) s4 = f(t00+h,y00+h*s3) y00 = y00+h/6*(s1+2*s2+2*s3+s4) t00=t00+h soln.append([t00,y00]) print "%10r %20r %20r"%(t00,y00,solution(t00))
0.500000000000000 1.64843750000000 1.64872127070013 1.00000000000000 2.71734619140625 2.71828182845905