import swiginac
import sys

if len(sys.argv) == 1:
	print "Usage: \"python firstorder.py \'$ODE\' '$IC'\" where $ODE is the ODE with y as dependent variable and x as independent variable and IC the initial condition"
	sys.exit(1)

x = swiginac.symbol('x')
y = swiginac.symbol('y')
F = eval(sys.argv[1])
IC = float(sys.argv[2])

def taylor(xx,FA,F,y0,hp):
	S = xx + FA #10-10
	FS = float(F.subs(x==S))
	print "FS", FS
	Y = xx+hp * FS #10-09
	print "Y", Y
	return Y

def step(F,y0, h, p):
	for i in range(p):
		y0 = [taylor(y0[0],FA[0],F,y0,h/p), taylor(y0[1],FA[1],F,y0,h/p)]
		print y0

h = 0.25
p = 2
A = [0.,2.]	 #example Moore1965interval p. 97
FA = (float(F.subs(x==A[0]))*h/p,float(F.subs(x==A[1]))*h/p)
print "FA", FA
y0 = [IC,IC]
step(F,y0, h, p)


