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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.