Example #1
0
def cplot_in_terminal(expr, *args, prec=None, logname=None, color=lambda i:
    -mpmath.floor(mpmath.log(abs(i), 10))/(30 -
        mpmath.floor(mpmath.log(abs(i), 10))), points=1000000, **kwargs):
    """
    Run mpmath.cplot() but show in terminal if possible
    """
    kwargs['color'] = color
    kwargs['points'] = points
    from mpmath import cplot
    if prec:
        mpmath.mp.dps = prec
    f = lambdify(t, expr, mpmath)
    try:
        from iterm2_tools.images import display_image_bytes
    except ImportError:
        if logname:
            os.makedirs('plots', exist_ok=True)
            file = 'plots/%s.png' % logname
        else:
            file = None
        cplot(f, *args, file=file, **kwargs)
    else:
        from io import BytesIO
        b = BytesIO()
        cplot(f, *args, **kwargs, file=b)
        if logname:
            os.makedirs('plots', exist_ok=True)
            with open('plots/%s.png' % logname, 'wb') as f:
                f.write(b.getvalue())
        print(display_image_bytes(b.getvalue()))
Example #2
0
def make_plots(n, rerange = [-7,7], imrange = [-7,7], numpoints = 20000, outdir = "./"):
	first_term = lambda z: 1/(z**2)
	lattice_points = make_lattice_points(n)
	print len(lattice_points)
	print lattice_points
	for i in range(len(lattice_points)+1):
		next_element = lambda z: first_term(z) + sum(make_w_term(lattice_point)(z) for lattice_point in lattice_points[0:i])
		print i
		cplot(next_element, re = rerange, im=imrange, file= outdir + "Weierstrass%03d.jpg" % i, points = numpoints)
Example #3
0
def make_plots(n, rerange = [-7,7], imrange = [-7,7], numpoints = 20000, outdir = "./", n_images=25):
	first_term = lambda z: 1/(z**2)
	lattice_points = make_lattice_points(n)
	print len(lattice_points)
	print lattice_points
	#this is O(n^2) but should be O(n) if I wrote it better:
	for i in range(n_images):
		next_element = lambda z: first_term(z) + sum(make_w_term(lattice_point)(z) for lattice_point in lattice_points[0:i])
		print i
		cplot(next_element, re = rerange, im=imrange, file= outdir + "Weierstrass%03d.png" % i, points = numpoints)
Example #4
0
async def graphc(msg, mobj):
    """
    Graph a complex equation (using mpmath functions and plotting)
    Equations should map to the complex domain
    Ex: !complex gamma(x)
    """
    fname = bot_data("{}.png".format(mobj.author.id))
    try:
        firstp = msg.split(",")
        func = firstp[0]
        expr = sympify(func)
        var = list(expr.free_symbols)[0]
        lamb = lambdify(var,
                        monkey_patch_function(sympify(func)),
                        modules=["mpmath"])
        cplot(lamb, points=sample_size, file=fname)
        await client.send_file(mobj.channel, fname)
        f_remove(fname)
        return
    except Exception as ex:
        logger("!graphc: {}".format(ex))
    return await client.send_message(mobj.channel, "Failed to render graph")
Example #5
0
def plot_state(k, rerange=[-30, 20], imrange=[-20, 20], points=10000):
    mpmath.cplot(lambda z: coherent_representation(vectors[:, k], z), rerange,
                 imrange, points)
Example #6
0
    return ham


def coherent_representation(state, zbar):
    polynom = 0
    monom = 1
    for i, c in enumerate(state):
        polynom += c * monom
        monom *= zbar / math.sqrt(i + 1)

    return math.exp(-0.5 * abs(zbar)**2) * polynom


N_E = 400
delta = -1
beta = 1 / 12**2
E = 2 / 3 / math.sqrt(3) * abs(delta)**1.5 / beta**0.5 * 0.8
print(E)

energies, vectors = eigh(nonlinear_oscillator(delta, beta, E, 500))


def plot_state(k, rerange=[-30, 20], imrange=[-20, 20], points=10000):
    mpmath.cplot(lambda z: coherent_representation(vectors[:, k], z), rerange,
                 imrange, points)


#plot_state(10)

mpmath.cplot(lambda z: z, [-1, 1], [-1, 1])
# -*- coding: utf-8 -*-
"""
@author: sriganesh /Brijesh Janardhanan

Plotting the Reimann Zeta function map in imaginary numberspace.

"""

import mpmath
import matplotlib

#This will take a long time to run. For a short run, reduce points to 1000.
mpmath.cplot(mpmath.zeta, [-10, 10], [0, 100], points = 5000, verbose=False)
Example #8
0
import matplotlib.pyplot as plt
import pylab
import os
from mpmath import cplot, zeta

# compley-plot.py zeichnet den eingefaerbten komplexen Graphen der
# Riemannschen Zetafunktion im Bereich Re(s) zwischen -15 und 15,
# und Im(s) zwischen -23 und 23. Dazu werden 10 Millionen einzelne
# Punkte betrachtet. Die Generierung beansprucht circa 3,5 Stunden.
# Zum Vergleich wird die Funktion f(z) = z betrachtet, die die
# Technik des Einfaerbens erklaeren soll.

#cplot(zeta, [-15,15], [-23,23], points=10000000, file='complex-plot.pdf', verbose=True)
#cplot(zeta, [-5,2.5], [-5,5], points=10000000, file='complex-plot-small.pdf', verbose=True)
#cplot(zeta, [-5,2.5], [-40,40], points=10000000, file='complex-plot-large.pdf', verbose=True)
#cplot(zeta, [-18,18], [-18,18], points=10000000, file='complex-plot-extended.pdf', verbose=True)
#os.system('open complex-plot.pdf')

#cplot(lambda z: z, [-5,5], [-5,5], points=500000, file='complex-plot-z.pdf', verbose=True)
#cplot(lambda z: z**2, [-5,5], [-5,5], points=500000, file='complex-plot-z2.pdf', verbose=True)
cplot(lambda z: (z**2) + 1, [-5, 5], [-5, 5],
      points=500000,
      file='complex-plot-z2+1.pdf',
      verbose=True)