#!/usr/bin/env python ### graph_iterate_log1.py -- Limit original points to pi i +/- ~100 # Steve Witham ess doubleyou at tiac remove-this dot net. # http://www.tiac.net/~sw from reportlab.pdfgen import canvas from reportlab.lib.pagesizes import letter, A4 from reportlab.lib.units import inch from arrowline import arrowLine from math import sqrt, pow, pi, e from cmath import log, exp, sinh, asinh from os import system # From iterate_log.py: e0 = ( 0.31813150520476413 + 1.3372357014306895j ) BIGGEST = pow(2.0,1023) * (2.0-pow(2.0,-52)) SMALLEST = pow(2,-1074) def graph_iterate_log(c): # choose some colors c.setStrokeColorRGB(0,0,0) c.setFillColorRGB(0,0,0) c.setFont("Helvetica", 14 ) c.drawString( 1 * inch, 10 * inch, "Iterated Complex Natural Log" ) # initial set of points: nPoints = 33 # points = [ 0j + (i+.5)/nPoints for i in range( nPoints ) ] original_points = [ (pi * 1j) + sinh( i/3.0 ) for i in range( -(nPoints-1)/2, nPoints-(nPoints-1)/2 ) ] pmin, pmax = original_points[0].real, original_points[-1].real c.setFont("Helvetica", 11 ) c.drawString( 1 * inch, 9.5 * inch, "Original points at y = pi range from x = %f to %+f ." % ( pmin, pmax ) ) c.drawString( 1 * inch, 9.25 * inch, "(Only those from about -5 to +5 are visible.)" ) # Set the origin in the middle of the page: c.translate( 8.5 * inch / 2, 11 * inch / 2 ) # Scale so that range of the graph is about +/- 5: # NOTE: THIS MEANS LINE WIDTHS AND FONTS AREN'T IN POINTS ANY MORE. c.scale( .7*inch, .7*inch ) point = 1/( .7*inch ) # Draw the axes: c.setLineWidth( .25 * point ) # c.line( -4,0, 4,0 ) # No x axis, it obscures the little arrows. c.line( 0,-4, 0,4 ) points = original_points for i in range(4): points = [ expsafe(z) for z in points ] c.setStrokeColorRGB( 1, 0, 0 ) for j in range( len(points) - 1 ): if j == len(points) / 2: c.setStrokeColorRGB( 0, 0, 0 ) if points[j] == None or points[ j+1 ] == None: continue size = abs( points[j] - points[j+1] ) if size < 10: c.setLineWidth( size / 10 ) arrowLine( c, points[j].real, points[j].imag, points[j+1].real, points[j+1].imag ) points = original_points for i in range(24): c.setStrokeColorRGB( 1, 0, 0 ) for j in range( len(points) - 1 ): if j == len(points) / 2: c.setStrokeColorRGB( 0, 0, 0 ) size = abs( points[j] - points[j+1] ) if size < 10 and ( abs(points[j])<10 or abs(points[j+1])<10 ): c.setLineWidth( size / 10 ) arrowLine( c, points[j].real, points[j].imag, points[j+1].real, points[j+1].imag ) points = [ log(z) for z in points ] ticks = [ -1, e**-1, 1, e**(e**-1), e, e**(e**(e**-1)) ] names = [ "-1", "e^-1", "1", "e^e^-1", "e", "e^e^e^-1" ] c.setFont("Helvetica", 10 * point ) c.setLineWidth( .25 * point ) for i in range( len( ticks ) ): x, name = ticks[i], names[i] c.line( x, -.3, x, -.1 ) printexp( c, x, -.55, name, "Helvetica", 10 * point ) def expsafe( z ): if z != None and abs(z) < 706: return exp(z) else: return None def printexp( c, x, y, name, fontname, fontsize ): width = c.stringWidth( name.replace('^',''), fontname, fontsize ) pieces = name.split( '^' ) jump = fontsize * .5 y -= ( len(pieces) - 1 ) * jump * .5 x -= width / 2 for piece in pieces: c.drawString( x, y, piece ) x += c.stringWidth( piece, fontname, fontsize ) y += jump output_file = "graph_iterate_log1.pdf" # pageCompression = 0 if I can look at the text in the output. # set to 1 in rl_config.py. c = canvas.Canvas( output_file, pagesize=letter ) width, height = letter #keep for later graph_iterate_log(c) c.showPage() c.save() system( "open " + output_file )