File:Mplwp arithmetic-geometric mean.svg

Summary

Description
English: Plot of the arithmetic–geometric mean of 1 and x vs. x.
Date
Source Own work
Author Geek3
SVG development
InfoField
 
The SVG code is valid.
 
This plot was created with mplwp, the Matplotlib extension for Wikipedia plots.
Category:Valid SVG created with mplwp code#Mplwp%20arithmetic-geometric%20mean.svg
Source code
InfoField

mplwp source code

The plot was generated with mplwp 1.7
#!/usr/bin/python
# -*- coding: utf8 -*-

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from math import *

code_website = 'http://commons.wikimedia.org/wiki/User:Geek3/mplwp'
try:
    import mplwp
except ImportError, er:
    print 'ImportError:', er
    print 'You need to download mplwp.py from', code_website
    exit(1)

name = 'mplwp_arithmetic-geometric_mean.svg'
fig = mplwp.fig_standard(mpl)

xlim = -0.05, 4.0; fig.gca().set_xlim(xlim)
ylim = 0, 2.5; fig.gca().set_ylim(ylim)
mplwp.mark_axeszero(fig.gca())

def agm(x, y):
    a, g = x, y
    for i in range(13):
        a, g = 0.5 * (a + g), sqrt(a * g)
        if fabs(a - g) / (a + g) < 1e-16:
            break
    return a

x = np.linspace(0, 4, 4001)

y0 = [xx for xx in x]
plt.plot(x, y0, ':', label='x', color='#00bb00', dashes=[3,3], zorder=1)

y1 = [0.5 * (1.0 + xx) for xx in x]
plt.plot(x, y1, '--', color='#00bbcc', dashes=[12,3], zorder=2,
    label=r'$\frac{1}{2}(1+x)$')

y2 = [agm(1.0, xx) for xx in x]
plt.plot(x, y2, '-', label=r'$agm(1, x)$', color='#0000cc', zorder=4)

y3 = [sqrt(1.0 * xx) for xx in x]
plt.plot(x, y3, '--', color='#dd00aa', dashes=[12,3], zorder=3,
    label=r'$\sqrt{1\cdot x}$')

y4 = [1.0 for xx in x]
plt.plot(x, y4, ':', label='1', color='#999900', dashes=[3,3], zorder=0)

plt.legend(loc='lower right')
plt.savefig(name)
mplwp.postprocess(name)

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Mplwp%20arithmetic-geometric%20mean.svg
Category:Self-published work Category:Function plots Category:Special functions
Category:CC-BY-SA-4.0 Category:Function plots Category:Self-published work Category:Special functions Category:Valid SVG created with mplwp code