plotsequence.py

Created by ews31415

Created on December 27, 2020

520 Bytes

Plot a one-level deep recurrence relation. In the def structure, u for u_n-1.


from math import *
from matplotlib.pyplot import *
# EWS 2020-12-26

# define parametric here
# u: u(n-1)
def w(u):
  f=sqrt(3*u+1)
  return f

# main routine
ui=float(input('initial? '))
n=float(input('n? '))

# build
xlist=[0]
ylist=[ui]
k=0

while k<n:
  k=k+1
  f=w(k)
  xp=k
  yp=f
  xlist.append(xp)
  ylist.append(yp)
  
# plot routine

# set axes
ya=min(ylist)
yb=max(ylist)
axis((0,n,ya,yb))
axis(True)

# select color, type color
ch="green"

# plot points
plot(xlist,ylist,color=ch)
show()