There's an extra space character before the s = <etc.> line in the if t == 0:
block.
On Jul 8, 2012, at 6:29 PM, Judson Wallace wrote:
> Euler's method for a differential
> ... i am only interested in writting the information if its at one of these
> values... problem is, i keep getting a syntax error with the if/then
> statements
>
> --------------------------------
>
> fout = open('/selftest.txt','w')
> var('t y')
> f(t,y) = 5-3*y^(1/2)
> t = 0.0
> y = 2.0
> steps = 60
> h = 0.05
> for i in range(steps +1):
> if t == 0:
> print 'i=', i, 't=', t, 'y=', y
> s ='i='+repr(i)+' t='+repr(t)+' y='+repr(y) +'\n' <== extra space
> before s =
> fout.write(s)
> y = (f(t,y)*h)+y
> t = t+h
> elif (t == 1.0):
> print 'i=', i, 't=', t, 'y=', y
> s ='i='+repr(i)+' t='+repr(t)+' y='+repr(y) +'\n'
> fout.write(s)
> y = (f(t,y)*h)+y
> t = t+h
> elif (t == 1.5):
> print 'i=', i, 't=', t, 'y=', y
> s ='i='+repr(i)+' t='+repr(t)+' y='+repr(y) +'\n'
> fout.write(s)
> y = (f(t,y)*h)+y
> t = t+h
> else:
> y = (f(t,y)*h)+y
> t = t+h
>
> fout.close()
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org