Exemple #1
0
def eqn_list_to_curve_plot(L, rat_pts):
    xpoly_rng = PolynomialRing(QQ, 'x')
    poly_tup = [xpoly_rng(tup) for tup in L]
    f = poly_tup[0]
    h = poly_tup[1]
    g = f + h**2 / 4
    if len(g.real_roots()) == 0 and g(0) < 0:
        return text(r"$X(\mathbb{R})=\emptyset$", (1, 1), fontsize=50)
    X0 = [real(z[0]) for z in g.base_extend(CC).roots()
          ] + [real(z[0]) for z in g.derivative().base_extend(CC).roots()]
    a, b = inflate_interval(min(X0), max(X0), 1.5)
    groots = [a] + g.real_roots() + [b]
    if b - a < 1e-7:
        a = -3
        b = 3
        groots = [a, b]
    ngints = len(groots) - 1
    plotzones = []
    npts = 100
    for j in range(ngints):
        c = groots[j]
        d = groots[j + 1]
        if g((c + d) / 2) < 0:
            continue
        (c, d) = inflate_interval(c, d, 1.1)
        s = (d - c) / npts
        u = c
        yvals = []
        for i in range(npts + 1):
            v = g(u)
            if v > 0:
                v = sqrt(v)
                w = -h(u) / 2
                yvals.append(w + v)
                yvals.append(w - v)
            u += s
        (m, M) = inflate_interval(min(yvals), max(yvals), 1.2)
        plotzones.append((c, d, m, M))
    x = var('x')
    y = var('y')
    plot = sum(
        implicit_plot(y**2 + y * h(x) - f(x), (x, R[0], R[1]), (y, R[2], R[3]),
                      aspect_ratio='automatic',
                      plot_points=500,
                      zorder=1) for R in plotzones)
    xmin = min([R[0] for R in plotzones])
    xmax = max([R[1] for R in plotzones])
    ymin = min([R[2] for R in plotzones])
    ymax = max([R[3] for R in plotzones])
    for P in rat_pts:
        (x, y, z) = P
        z = ZZ(z)
        if z:  # Do not attempt to plot points at infinity
            x = ZZ(x) / z
            y = ZZ(y) / z**3
            if x >= xmin and x <= xmax and y >= ymin and y <= ymax:
                plot += point((x, y), color='red', size=40, zorder=2)
    return plot
Exemple #2
0
 def __init__(self, implicit_curve, xrange, yrange, plot_points=300):
     ObjectGraph.__init__(self, implicit_curve)
     GeometricImplicitCurve.__init__(self, implicit_curve.f)
     self.implicit_curve = implicit_curve
     self.implicit_plot = implicit_plot(self.f, xrange, yrange)
     self.xrange = xrange
     self.yrange = yrange
     self.plot_points = plot_points
     self.paths = get_paths_from_implicit_plot(self.implicit_plot)
     self.parameters.color = "blue"
Exemple #3
0
def eqn_list_to_curve_plot(L,rat_pts):
    xpoly_rng = PolynomialRing(QQ,'x')
    poly_tup = [xpoly_rng(tup) for tup in L]
    f = poly_tup[0]
    h = poly_tup[1]
    g = f+h**2/4
    if len(g.real_roots())==0 and g(0)<0:
        return text("$X(\mathbb{R})=\emptyset$",(1,1),fontsize=50)
    X0 = [real(z[0]) for z in g.base_extend(CC).roots()]+[real(z[0]) for z in g.derivative().base_extend(CC).roots()]
    a,b = inflate_interval(min(X0),max(X0),1.5)
    groots = [a]+g.real_roots()+[b]
    if b-a<1e-7:
        a=-3
        b=3
        groots=[a,b]
    ngints = len(groots)-1
    plotzones = []
    npts = 100
    for j in range(ngints):
        c = groots[j]
        d = groots[j+1]
        if g((c+d)/2)<0:
            continue
        (c,d) = inflate_interval(c,d,1.1)
        s = (d-c)/npts
        u = c
        yvals = []
        for i in range(npts+1):
            v = g(u)
            if v>0:
                v = sqrt(v)
                w = -h(u)/2
                yvals.append(w+v)
                yvals.append(w-v)
            u += s
        (m,M) = inflate_interval(min(yvals),max(yvals),1.2)
        plotzones.append((c,d,m,M))
    x = var('x')
    y = var('y')
    plot=sum(implicit_plot(y**2 + y*h(x) - f(x), (x,R[0],R[1]),(y,R[2],R[3]), aspect_ratio='automatic', plot_points=500, zorder=1) for R in plotzones)
    xmin=min([R[0] for R in plotzones])
    xmax=max([R[1] for R in plotzones])
    ymin=min([R[2] for R in plotzones])
    ymax=max([R[3] for R in plotzones])
    for P in rat_pts:
    	(x,y,z)=eval(P.replace(':',','))
        z=ZZ(z)
     	if z: # Do not attempt to plot points at infinity
      		x=ZZ(x)/z
      		y=ZZ(y)/z**3
      		if x >= xmin and x <= xmax and y >= ymin and y <= ymax:
       			plot += point((x,y),color='red',size=40,zorder=2)
    return plot
Exemple #4
0
def eqn_list_to_curve_plot(L):
    xpoly_rng = PolynomialRing(QQ, 'x')
    poly_tup = [xpoly_rng(tup) for tup in L]
    f = poly_tup[0]
    h = poly_tup[1]
    g = f + h**2 / 4
    if len(g.real_roots()) == 0 and g(0) < 0:
        return text("$X(\mathbb{R})=\emptyset$", (1, 1), fontsize=50)
    X0 = [real(z[0]) for z in g.base_extend(CC).roots()
          ] + [real(z[0]) for z in g.derivative().base_extend(CC).roots()]
    a, b = inflate_interval(min(X0), max(X0), 1.5)
    groots = [a] + g.real_roots() + [b]
    if b - a < 1e-7:
        a = -3
        b = 3
        groots = [a, b]
    ngints = len(groots) - 1
    plotzones = []
    npts = 100
    for j in range(ngints):
        c = groots[j]
        d = groots[j + 1]
        if g((c + d) / 2) < 0:
            continue
        (c, d) = inflate_interval(c, d, 1.1)
        s = (d - c) / npts
        u = c
        yvals = []
        for i in range(npts + 1):
            v = g(u)
            if v > 0:
                v = sqrt(v)
                w = -h(u) / 2
                yvals.append(w + v)
                yvals.append(w - v)
            u += s
        (m, M) = inflate_interval(min(yvals), max(yvals), 1.2)
        plotzones.append((c, d, m, M))
    x = var('x')
    y = var('y')
    return sum(
        implicit_plot(
            y**2 + y * h(x) - f(x), (x, R[0], R[1]), (y, R[2], R[3]),
            aspect_ratio='automatic',
            plot_points=500) for R in plotzones)
Exemple #5
0
def eqn_list_to_curve_plot(L):
    xpoly_rng = PolynomialRing(QQ, 'x')
    poly_tup = [xpoly_rng(tup) for tup in L]
    f = poly_tup[0]
    h = poly_tup[1]
    g = f + h**2 / 4
    if len(g.real_roots()) == 0 and g(0) < 0:
        return text("$X(\mathbb{R})=\emptyset$", (1, 1), fontsize=50)
    X0 = [real(z[0]) for z in g.base_extend(CC).roots()
          ] + [real(z[0]) for z in g.derivative().base_extend(CC).roots()]
    a, b = inflate_interval(min(X0), max(X0), 1.5)
    groots = [a] + g.real_roots() + [b]
    if b - a < 1e-7:
        a = -3
        b = 3
        groots = [a, b]
    ngints = len(groots) - 1
    plotzones = []
    npts = 100
    for j in range(ngints):
        c = groots[j]
        d = groots[j + 1]
        if g((c + d) / 2) < 0:
            continue
        (c, d) = inflate_interval(c, d, 1.1)
        s = (d - c) / npts
        u = c
        yvals = []
        for i in range(npts + 1):
            v = g(u)
            if v > 0:
                v = sqrt(v)
                w = -h(u) / 2
                yvals.append(w + v)
                yvals.append(w - v)
            u += s
        (m, M) = inflate_interval(min(yvals), max(yvals), 1.2)
        plotzones.append((c, d, m, M))
    x = var('x')
    y = var('y')
    return sum(
        implicit_plot(y**2 + y * h(x) - f(x), (x, R[0], R[1]), (y, R[2], R[3]),
                      aspect_ratio='automatic',
                      plot_points=500) for R in plotzones)
Exemple #6
0
def EC_R_plot(ainvs, xmin, xmax, ymin, ymax, colour, legend):
    x = var('x')
    y = var('y')
    c = (xmin + xmax) / 2
    d = (xmax - xmin)
    return implicit_plot(
        y**2 + ainvs[0] * x * y + ainvs[2] * y - x**3 - ainvs[1] * x**2 -
        ainvs[3] * x - ainvs[4], (x, xmin, xmax), (y, ymin, ymax),
        plot_points=500,
        aspect_ratio="automatic",
        color=colour
    ) + plot(
        0,
        xmin=c - 1e-5 * d,
        xmax=c + 1e-5 * d,
        ymin=ymin,
        ymax=ymax,
        aspect_ratio="automatic",
        color=colour,
        legend_label=legend
    )  # Add an extra plot outside the visible frame because implicit plots are buggy: their legend does not show (http://trac.sagemath.org/ticket/15903)
Exemple #7
0
def EC_R_plot(ainvs, xmin, xmax, ymin, ymax, colour, legend):
    x = var("x")
    y = var("y")
    c = (xmin + xmax) / 2
    d = xmax - xmin
    return implicit_plot(
        y ** 2 + ainvs[0] * x * y + ainvs[2] * y - x ** 3 - ainvs[1] * x ** 2 - ainvs[3] * x - ainvs[4],
        (x, xmin, xmax),
        (y, ymin, ymax),
        plot_points=1000,
        aspect_ratio="automatic",
        color=colour,
    ) + plot(
        0,
        xmin=c - 1e-5 * d,
        xmax=c + 1e-5 * d,
        ymin=ymin,
        ymax=ymax,
        aspect_ratio="automatic",
        color=colour,
        legend_label=legend,
    )  # Add an extra plot outside the visible frame because implicit plots are buggy: their legend does not show (http://trac.sagemath.org/ticket/15903)