Ask Your Question

Revision history [back]

Whitespace is important in SageMath (as in Python). The body of a function needs to be indented, so everything inside the function should be indented (e.g. by four spaces). Similarly, the body of a for-loop needs to be indented. This should be the correct indentation (I did not check anything else):

def ell_geom_animation(E,init_points,n_points=10):
    var('x,y')
    #E = EllipticCurve(y^2==x^3-82*x);
    p = init_points
    j = len(p)
    ell_frames = [plot(E)]*(n_points+j)
    point_plots = []
    line_plots = []
    point_frames = []
    line_frames = []
    for i in srange(0,j-1):
        point_plots += point(p[i][0:2],color='black',size=10)
    for i in srange(0,n_points):
        p += [E(p[i]+p[i+1])]
        point_plots += point(p[j+i][0:2],color='black',size=10)
        point_frames.append(point_plots)
        line_plots += line([p[i][0:2],p[i+1][0:2]],color='black',size=10)
        line_frames.append(line_plots)
    A1 = animate(ell_frames)
    A2 = animate(point_frames)
    A3 = animate(line_frames)
    return show(A1+A2+A3) # superimpose frame

In your snippet some of the code was outside of the function, so local variables were not defined.

Whitespace is important in SageMath (as in Python). The body of a function needs to be indented, so everything inside the function should be indented (e.g. by four spaces). Similarly, the body of a for-loop needs to be indented. This should be the correct indentation (I did not check anything else):

def ell_geom_animation(E,init_points,n_points=10):
    var('x,y')
    #E = EllipticCurve(y^2==x^3-82*x);
    p = init_points
    j = len(p)
    ell_frames = [plot(E)]*(n_points+j)
    point_plots = []
    line_plots = []
    point_frames = []
    line_frames = []
    for i in srange(0,j-1):
        point_plots += point(p[i][0:2],color='black',size=10)
    for i in srange(0,n_points):
        p += [E(p[i]+p[i+1])]
        point_plots += point(p[j+i][0:2],color='black',size=10)
        point_frames.append(point_plots)
        line_plots += line([p[i][0:2],p[i+1][0:2]],color='black',size=10)
        line_frames.append(line_plots)
    A1 = animate(ell_frames)
    A2 = animate(point_frames)
    A3 = animate(line_frames)
    return show(A1+A2+A3) # superimpose frame

In your snippet some of the code was outside of the function, so local variables were not defined.


Instead of removing the leading dots (from the Sage command line) you should replace them by spaces.

Whitespace is important in SageMath (as in Python). The body of a function needs to be indented, so everything inside the function should be indented (e.g. by four spaces). Similarly, the body of a for-loop needs to be indented. This should be the correct indentation (I did not check anything else):

def ell_geom_animation(E,init_points,n_points=10):
    var('x,y')
    #E = EllipticCurve(y^2==x^3-82*x);
    p = init_points
    j = len(p)
    ell_frames = [plot(E)]*(n_points+j)
    point_plots = []
    line_plots = []
    point_frames = []
    line_frames = []
    for i in srange(0,j-1):
        point_plots += point(p[i][0:2],color='black',size=10)
    for i in srange(0,n_points):
        p += [E(p[i]+p[i+1])]
        point_plots += point(p[j+i][0:2],color='black',size=10)
        point_frames.append(point_plots)
        line_plots += line([p[i][0:2],p[i+1][0:2]],color='black',size=10)
        line_frames.append(line_plots)
    A1 = animate(ell_frames)
    A2 = animate(point_frames)
    A3 = animate(line_frames)
    return show(A1+A2+A3) # superimpose frame

In your snippet some of the code was outside of the function, so local variables were not defined.


Instead of removing the leading dots (from the Sage command line) you should replace them by spaces.


To avoid copying and pasting you can also try the Jupyter Notebook interface.

Whitespace is important in SageMath (as in Python). The body of a function needs to be indented, so everything inside the function should be indented (e.g. by four spaces). Similarly, the body of a for-loop needs to be indented. This should be the correct indentation (I did not check anything else):

def ell_geom_animation(E,init_points,n_points=10):
    var('x,y')
    #E = EllipticCurve(y^2==x^3-82*x);
    p = init_points
    j = len(p)
    ell_frames = [plot(E)]*(n_points+j)
    point_plots = []
    line_plots = []
    point_frames = []
    line_frames = []
    for i in srange(0,j-1):
        point_plots += point(p[i][0:2],color='black',size=10)
    for i in srange(0,n_points):
        p += [E(p[i]+p[i+1])]
        point_plots += point(p[j+i][0:2],color='black',size=10)
        point_frames.append(point_plots)
        line_plots += line([p[i][0:2],p[i+1][0:2]],color='black',size=10)
        line_frames.append(line_plots)
    A1 = animate(ell_frames)
    A2 = animate(point_frames)
    A3 = animate(line_frames)
    return show(A1+A2+A3) # superimpose frame

In your snippet some of the code was outside of the function, so local variables were not defined.


Instead of removing the leading dots (from the Sage command line) you should replace them by spaces.


To avoid copying and pasting you can also try load a file from the command line, or use the Jupyter Notebook interface.interface instead.