Ticket #11273: trac_11273-fix.patch

File trac_11273-fix.patch, 9.3 KB (added by evanandel, 9 years ago)
  • sage/calculus/riemann.pyx

    # HG changeset patch
    # User Ethan Van Andel <evlutte@gmail.com>
    # Date 1347401807 25200
    # Node ID 5eff831f4f25bc1207ff283e13a229ddbaea028d
    # Parent  c936a538f8f7a9f7a468620541cb8d8032005892
    trac 11273: Minor doc/polish fixes.
    
    diff --git a/sage/calculus/riemann.pyx b/sage/calculus/riemann.pyx
    a b  
    106106      the origin of the unit disc. Note that ``a`` MUST be within
    107107      the region in order for the results to be mathematically valid.
    108108
    109     The following inputs must all be passed in as named parameters:
     109    The following inputs may be passed in as named parameters:
    110110
    111111    - ``N`` -- integer (default: ``500``), the number of collocation points
    112112      used to compute the map. More points will give more accurate results,
     
    137137        sage: f(t) = e^(I*t)
    138138        sage: fprime(t) = I*e^(I*t)
    139139        sage: m = Riemann_Map([f], [fprime], 0)  # long time (4 sec)
     140        sage: m.plot_colored() + m.plot_spiderweb()  # long time
     141       
     142    The exterior map for the unit circle::
     143   
     144        sage: m = Riemann_Map([f], [fprime], 0, exterior=True)  # long time (4 sec)
     145        sage: #spiderwebs are not supported for exterior maps
     146        sage: m.plot_colored() # long time
    140147
    141148    The unit circle with a small hole::
    142149
     
    145152        sage: hf(t) = 0.5*e^(-I*t)
    146153        sage: hfprime(t) = 0.5*-I*e^(-I*t)
    147154        sage: m = Riemann_Map([f, hf], [fprime, hfprime], 0.5 + 0.5*I)
    148         sage: m.plot_colored() + m.plot_spiderweb()  # long time
     155        sage: #spiderweb and color plots cannot be added for multiply
     156        sage: #connected regions. Instead we do this.
     157        sage: m.plot_spiderweb(withcolor = True)  # long time
    149158
    150159    A square::
    151160
     
    225234            self.tk2[i] = self.tk[i]
    226235        self.tk2[N] = TWOPI
    227236        self.B = len(fs) # number of boundaries of the figure
    228         if exterior and (self.B > 1):
     237        if self.exterior and (self.B > 1):
    229238            raise ValueError(
    230239                "The exterior map is undefined for multiply connected domains")
    231240        cdef np.ndarray[COMPLEX_T,ndim=2] cps = np.zeros([self.B, N],
     
    244253                for i in xrange(N):
    245254                    cps[k, i] = np.complex(fs[k](self.tk[i]))
    246255                    dps[k, i] = np.complex(fprimes[k](self.tk[i]))
    247         if exterior:
     256        if self.exterior:
    248257            xmax = (1/cps).real.max()
    249258            xmin = (1/cps).real.min()
    250259            ymax = (1/cps).imag.max()
     
    369378
    370379        INPUT:
    371380
    372         The following inputs must all be passed in as named parameters:
     381        The following inputs may be passed in as named parameters:
    373382
    374383        - ``boundary`` -- integer (default: ``-1``) if < 0,
    375384          :meth:`get_theta_points` will return the points for all boundaries.
     
    699708
    700709        INPUT:
    701710
    702         The following inputs must all be passed in as named parameters:
     711        The following inputs may be passed in as named parameters:
    703712
    704713        - ``plotjoined`` -- boolean (default: ``True``) If ``False``,
    705714          discrete points will be drawn; otherwise they will be connected
     
    818827        may exhibit erratic behavior near the boundary; if this occurs,
    819828        decreasing ``linescale`` may mitigate the problem.
    820829
    821         Note that this method requires significantly more computation for
    822         multiply connected domains.
     830        For multiply connected domains the spiderweb is by necessity
     831        generated using the forward mapping. This method is more
     832        computationally intensive. In addition, these spiderwebs cannot
     833        be ``added`` to color plots. Instead the ``withcolor`` option
     834        must be used.
     835       
     836        In addition, spiderweb plots are not currently supported for
     837        exterior maps.
    823838
    824839        INPUT:
    825840
    826         The following inputs must all be passed in as named parameters:
     841        The following inputs may be passed in as named parameters:
    827842
    828843        - ``spokes`` -- integer (default: ``16``) the number of equally
    829844          spaced radial lines to plot.
     
    889904            sage: m.plot_spiderweb()
    890905        """
    891906        cdef int k, i
     907        if self.exterior:
     908            raise ValueError(
     909                "Spiderwebs for exterior maps are not currently    supported")
    892910        if self.B == 1: #The efficient simply connected
    893911            edge = self.plot_boundaries(plotjoined=plotjoined,
    894912                rgbcolor=rgbcolor, thickness=thickness)
     
    955973
    956974        INPUT:
    957975
    958         The following inputs must all be passed in as named parameters:
     976        The following inputs may be passed in as named parameters:
    959977
    960978        - ``plot_range`` -- (default: ``[]``) list of 4 values
    961979          ``(xmin, xmax, ymin, ymax)``. Declare if you do not want the plot
     
    10761094    jmax = len(z_values[0])-2
    10771095    #(f(x+delta)-f(x-delta))/2delta
    10781096    xderiv = (z_values[1:-1,2:]-z_values[1:-1,:-2])/(2*xstep)
    1079     #b/c the function is analytic, we know its abs(derivative) is equal
    1080     #in all directions
     1097    #b/c the function is analytic, we know the magnitude of its
     1098    #derivative is equal in all directions
    10811099    dr = np.abs(xderiv)
    10821100    # the abs(derivative) scaled by distance from origin
    10831101    zabs = np.abs(z_values[1:-1,1:-1])
     
    13011319    sig_off()
    13021320    return rgb
    13031321
    1304 cpdef analytic_boundary(FLOAT_T t, int n):
     1322cpdef analytic_boundary(FLOAT_T t, int n, FLOAT_T epsilon):
    13051323    """
    13061324    Provides an exact (for n = infinity) Riemann boundary
    13071325    correspondence for the ellipse with axes 1 + epsilon and 1 - epsilon. The
     
    13141332
    13151333    - ``n`` -- integer - the number of terms to include.
    13161334      10 is fairly accurate, 20 is very accurate.
     1335     
     1336    - ``epsilon`` -- float - the skew of the ellipse (0 is circular)
    13171337
    13181338    OUTPUT:
    13191339
     
    13251345    Checking the accuracy of this function for different n values::
    13261346
    13271347        sage: from sage.calculus.riemann import analytic_boundary
    1328         sage: t100 = analytic_boundary(pi/2,100)
    1329         sage: abs(analytic_boundary(pi/2,10) - t100) < 10^-8
     1348        sage: t100 = analytic_boundary(pi/2, 100, .3)
     1349        sage: abs(analytic_boundary(pi/2, 10, .3) - t100) < 10^-8
    13301350        True
    1331         sage: abs(analytic_boundary(pi/2,20) - t100) < 10^-15
     1351        sage: abs(analytic_boundary(pi/2, 20, .3) - t100) < 10^-15
    13321352        True
    13331353
    13341354    Using this to check the accuracy of the Riemann_Map boundary::
     
    13381358        sage: m = Riemann_Map([f], [fp],0,200)
    13391359        sage: s = spline(m.get_theta_points())
    13401360        sage: test_pt = uniform(0,2*pi)
    1341         sage: s(test_pt) - analytic_boundary(test_pt,20) < 10^-4
     1361        sage: s(test_pt) - analytic_boundary(test_pt,20, .3) < 10^-4
    13421362        True
    13431363    """
    13441364    cdef FLOAT_T i
    13451365    cdef FLOAT_T result = t
    13461366    for i from 1 <= i < n+1:
    1347         result += (2*(-1)**i/i)*(.3**i/(1+.3**(2*i)))*sin(2*i*t)
     1367        result += (2*(-1)**i/i)*(epsilon**i/(1+epsilon**(2*i)))*sin(2*i*t)
    13481368    return result
    13491369
    13501370
     
    13581378    - ``t`` -- The boundary parameter, meant to be integrated over
    13591379
    13601380    - ``args`` -- a tuple containing:
     1381   
     1382      - ``epsilon`` -- float - the skew of the ellipse (0 is circular)
    13611383
    13621384      - ``z`` -- complex - the point to be mapped.
    13631385
     
    13731395    Here is a simple test::
    13741396
    13751397        sage: from sage.calculus.riemann import cauchy_kernel
    1376         sage: cauchy_kernel(.5,(.1+.2*I, 10,'c'))
     1398        sage: cauchy_kernel(.5,(.3, .1+.2*I, 10,'c'))
    13771399        (-0.584136405997...+0.5948650858950...j)
    13781400    """
    13791401    cdef COMPLEX_T result
    1380     cdef COMPLEX_T z = args[0]
    1381     cdef int n = args[1]
    1382     part = args[2]
    1383     result = exp(I*analytic_boundary(t,n))/(exp(I*t)+.3*exp(-I*t)-z) *  \
    1384         (I*exp(I*t)-I*.3*exp(-I*t))
     1402    cdef FLOAT_T epsilon = args[0]
     1403    cdef COMPLEX_T z = args[1]
     1404    cdef int n = args[2]
     1405    part = args[3]
     1406    result = exp(I*analytic_boundary(t,n, epsilon))/(exp(I*t)+epsilon*exp(-I*t)-z) *  \
     1407        (I*exp(I*t)-I*epsilon*exp(-I*t))
    13851408    if part == 'c':
    13861409        return result
    13871410    elif part == 'r':
     
    13901413        return result.imag
    13911414    else: return None
    13921415
    1393 cpdef analytic_interior(COMPLEX_T z, int n):
     1416cpdef analytic_interior(COMPLEX_T z, int n, FLOAT_T epsilon):
    13941417    """
    13951418    Provides a nearly exact compuation of the Riemann Map of an interior
    13961419    point of the ellipse with axes 1 + epsilon and 1 - epsilon. It is
     
    14111434        sage: f(t) = e^(I*t)+.3*e^(-I*t)
    14121435        sage: fp(t) = I*e^(I*t)-I*.3*e^(-I*t)
    14131436        sage: m = Riemann_Map([f],[fp],0,200)
    1414         sage: abs(m.riemann_map(.5)-analytic_interior(.5,20)) < 10^-4
     1437        sage: abs(m.riemann_map(.5)-analytic_interior(.5, 20, .3)) < 10^-4
    14151438        True
    14161439        sage: m = Riemann_Map([f],[fp],0,2000)
    1417         sage: abs(m.riemann_map(.5)-analytic_interior(.5,20)) < 10^-6
     1440        sage: abs(m.riemann_map(.5)-analytic_interior(.5, 20, .3)) < 10^-6
    14181441        True
    14191442    """
    14201443    # evaluates the cauchy integral of the boundary, split into the real
    14211444    # and imaginary results because numerical_integral can't handle complex data.
    14221445    rp = 1/(TWOPI)*numerical_integral(cauchy_kernel,0,2*pi,
    1423         params = [z,n,'i'])[0]
     1446        params = [epsilon,z,n,'i'])[0]
    14241447    ip = 1/(TWOPI*I)*numerical_integral(cauchy_kernel,0,2*pi,
    1425         params = [z,n,'r'])[0]
     1448        params = [epsilon,z,n,'r'])[0]
    14261449    return rp + ip