If you see this, something is wrong
First published on Tuesday, Feb 24, 2026 and last modified on Tuesday, Feb 24, 2026
Draw a Sequence
This is the web output of the basic sample document.
Now let's draw sequences, with numpy and matplotlib.pyplot.
The first thing we have to do is to get numpy and matplotlib.pyplot available.
For that we type from numpy import *, from matplotlib.pyplot import *.
from numpy import *
from matplotlib.pyplot import *For that we type from numpy import *, from matplotlib.pyplot import *.
But to draw sequences we must first define the sequences.
The first method is to use a sequential loop for.
For the sequences u equal to n and v equal to 2n, we use vectors initialized to zero, u equals zeros of 101, v equals zeros of 101.
And then the loop for, for n in arange of 101, u of n into brackets is equal to n and v of n into brackets is equal to 2 * n, 2 multiplied by n.
for w_n equal to 1 over n plus 1, and not 1 over n because it would derive in the division by zero.
We initialize w as a vector filled with zeros of size 50.
And then for n in arange of 50, w of n is 1 over n+1.
from numpy import *
from matplotlib.pyplot import *
u=zeros([101])
v=zeros([101])
for n in arange(101):
u[n]=n
v[n]=2*n
w=zeros([50])
for n in arange(50):
w[n]=1/(n+1)And then we may plot the sequences u, v and w.
Just launch Anaconda and Spyder and follow me to see how to do that.
We first type from numpy import star, and from matplotlib dot pyplot import star.
from numpy import *
from matplotlib.pyplot import *First we initialize the vector u that is for the sequence starting from zero.
It is filled with zeros and of length 101.
The indexes are from 0 to 100.
Then we define the vector v with the same vector.
And then we define the sequences u and v in the vectors.
for n in arange of 101, from 0 to 100, double point, u bracket n bracket is equal to n.
v bracket n is 2 multiplied by n.
We have our sequences.
Then we plot u, and on the same figure we plot v, separated by comma, the two plots.
And we have our two sequences.
u is in blue and v is in orange.
from numpy import *
from matplotlib.pyplot import *
for n in arange(101):
u[n]=n
v[n]=2*n
figure()
plot(u)
plot(v)
grid()
title('$u_n$ = n, $v_n$ = 2n')Then we define the sequence w.
We initialize it as a vector filled with zeros and of length 50, indexes are from 0 to 49.
for n in arange of 50, from 0 to 49, double point, w of n, into brackets, is equal to 1 over n plus 1.
n plus 1 goes from 1 to 50.
Then we plot w.
And we have the sequence w that is an arch of hyperbola.
from numpy import *
from matplotlib.pyplot import *
for n in arange(101):
u[n]=n
v[n]=2*n
figure()
plot(u)
plot(v)
grid()
title('$u_n$ = n, $v_n$ = 2n')
w=zeros([50])
for n in arange(50):
w[n]=1/(n+1)
figure()
plot(w)
grid()
title('$w_n$ = 1/(n+1)')But let's see another method to define directly sequences, with the arange based vectors and element by element operations on the arange based vector.
For u_n equals n, it is just the vector u equals arange of 101.
Or what else than 101.
For v_n equals to 2n, we may define the vector 2 multiplied by arange of 101, because the multiplication by 2 is made element by element on the vector arange of 101.
For w_n equal to 1 over n plus 1, we may use the vector arange of 1 and 51, that is made of the integers from 1 to 50, and then divide 1 by the elements of arange of 1, 51.
And then we may plot the sequences u, v and w.
Launch Anaconda and Spyder, to see another method to do this.
We shall use the editor.
We define a new file.
We give it a name.
We save it in the directory we wish.
to see it, and we give it the name sequences plotting dot py.
We first type from numpy import * and from matplotlib dot pyplot import star.
Then we define the sequence u directly as a vector.
u is equal to arange of 101.
So we have a vector made of all the integers from 0 to 100, and u is equal to n.
And v is two star arange of 101.
Then we have the doubles of the integers from 0 to 100.
Then we type figure with opening and closing parentheses, to define a new figure.
Then we plot u in the figure.
We plot v in the figure.
And then we add a grid, grid with opening and closing parenthese.s And we define a title u_n into dollars, so that we have u index n, is equal to n and v_n into dollars, so that we have a subscribe as n, is equal to 2n, quote, parenthesis.
file save and then run.
And we have our two plots with a grid and a title.
Now we shall define w based on this definition of u and v.
We copy and paste.
We will have another figure because we have figure in the text.
w is 1 over arange of 1 and 51.
We don't have any more v.
Figure, to have another figure, plot w.
We don't have to plot v.
grid and title, w index n is one over n plus one.
file > save, run > run.
And then we have our two figures.
from numpy import *
from matplotlib.pyplot import *
u=arange(101)
v=2*arange(101)
figure()
plot(u)
plot(v)
grid()
title('$u_n$ = n, $v_n$ = 2n')
w=1/arange(1,51)
figure()
plot(w)
grid()
title('$w_n$ = 1/(n+1)')What's coming now? What's coming now is to learn to draw a function, with numpy and matiplotlib.py plot as well.
Straight Lines
Aech of Hyperbola