X = [i/50-1 for i in range(101)]
plt.show()
plt.xticks(pos,labs)
where pos
is the positions of the ticks and labs
is the labelsimport matplotlib.pyplot as plt
from math import e
x_vals = [i/30 for i in range(91)]
y_vals = [e**i for i in x_vals]
plt.plot(x_vals,y_vals)
plt.show()
Let's solve the congruence equation $$ 3x^2 - 4x - 7 \equiv 0 \mod n $$ for various values of $ n $.
"""Write a function that takes n as input and finds all the positive solutions x < n"""
def cong_solns(n): # the input is a positive integer
solns = []
for x in range(n):
if (3*x**2-4*x-7)%n == 0:
solns.append(x)
return solns
cong_solns(4)
inputs = []
outputs = []
for n in range(100):
solns = cong_solns(n)
outputs += solns
for x in solns:
inputs.append(n)
plt.plot(inputs,outputs,'.')
plt.show()
Exercise: Write a function that takes two integers as input and returns their GCD.