aboutsummaryrefslogtreecommitdiffstats
path: root/buch/papers/laguerre/scripts/rel_error_complex.py
blob: 4a714fa32fa67d1f2c0a5b860d15fde1ed87ec22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
if __name__ == "__main__":
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import numpy as np
    import scipy.special

    import gamma_approx as ga

    mpl.rcParams.update(
        {
            "mathtext.fontset": "stix",
            "font.family": "serif",
            "font.serif": "TeX Gyre Termes",
        }
    )
    
    xmax = 4
    vals = np.linspace(-xmax + ga.EPSILON, xmax, 100)
    x, y = np.meshgrid(vals, vals)
    mesh = x + 1j * y
    input = mesh.flatten()

    lanczos = scipy.special.gamma(mesh)
    lag = ga.eval_laguerre_gamma(input, n=8, func="optimal_shifted").reshape(mesh.shape)
    rel_error = np.abs(ga.calc_rel_error(lanczos, lag))

    fig, ax = plt.subplots(clear=True, constrained_layout=True, figsize=(3.5, 2.1))
    _c = ax.pcolormesh(
        x, y, rel_error, shading="gouraud", cmap=ga.cmap, norm=mpl.colors.LogNorm()
    )
    cbr = fig.colorbar(_c, ax=ax)
    cbr.minorticks_off()
    # ax.set_title("Relative Error")
    ax.set_xlabel("Re($z$)")
    ax.set_ylabel("Im($z$)")
    minor_ticks = np.arange(-xmax, xmax + ga.EPSILON)
    ticks = np.arange(-xmax, xmax + ga.EPSILON, 2)
    ax.set_xticks(ticks)
    ax.set_xticks(minor_ticks, minor=True)
    ax.set_yticks(ticks)
    ax.set_yticks(minor_ticks, minor=True)
    fig.savefig(f"{ga.img_path}/rel_error_complex.pdf")
    # plt.show()