Python program errors -
i'm writing program needs find pairs of initial conditions (x0,y0) x goes extinct first , plot them.the equations are:
j=x-y+100 , i=x+y-100
and constraints (0,200) in both x , y directions.
my code looks this:
for x in range (0,201): y in range (0,201): c=0 i=x j=y while (x > 0 , y > 0): i=x-y+100 j=x+y-100 c=c+1 if i==0: plot(i,j) if c==50: break
and error says:
traceback (most recent call last): i=x-y+100 file "", line 1, in <module> file "/tmp/tmpqtzdaj/___code___.py", line 3, in <module> exec compile(u'for x in range (_sage_const_0 ,_sage_const_201 ):\n y in range (_sage_const_0 ,_sage_const_201 ):\n c=_sage_const_0 \n i=x\n j=y\n while (x > _sage_const_0 , y > _sage_const_0 ):\n i=x-y+_sage_const_100 \n j=x+y-_sage_const_100 \n c=c+_sage_const_1 \n if i==_sage_const_0 :\n plot([i],[j])\n if c==_sage_const_50 :\n break file "", line 11, in <module> file "/app/sage/sage-6.1.1/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 692, in wrapper return func(*args, **kwds) file "/app/sage/sage-6.1.1/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 537, in wrapper return func(*args, **options) file "/app/sage/sage-6.1.1/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1134, in plot g = _plot(funcs, *args, **kwds) file "/app/sage/sage-6.1.1/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1236, in _plot funcs, ranges = setup_for_eval_on_grid(funcs, [xrange], options['plot_points']) file "/app/sage/sage-6.1.1/local/lib/python2.7/site-packages/sage/plot/misc.py", line 132, in setup_for_eval_on_grid range_steps = [abs(range[1] - range[0])/(p-1) range, p in zip(ranges, plot_points)] indexerror: list index out of range
the problem passing integer plot()
when expects array.
at point internally, tries length of array , fails because can't take length of integer.
at guess, code should like
max_reps = 50 good_pts = [] x in range (0,201): y in range (0,201): c in range(max_reps): x, y = x - y + 100, x + y - 100 if y <= 0: break elif x <= 0: good_pts.append((x, y)) break
then plot (x, y) points in good_pts
.
Comments
Post a Comment