Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

​import matplotlib.

pyplot as plt
import math
# f(x) = e^(-|x|) * cos(2 * PI * x)

class Point2D:
def __init__(self, x = 0):
self.x = x
def fX(self, x):
result = 0
result = math.exp(abs(-x)) * math.cos(2*math.pi*x)
return result

graph = []
numPoints = int(input("Please enter the number of points that you would like to
graph with the function given: f(x) = e^(-|x|) * cos(2 * PI * x)"))
count = 0

while count != numPoints:


x = float(input("Enter a value for x to create a point (x, f(x)):"))
point = Point2D(x)
result = point.fX(x)
graph.append(result)
count += 1
for i in range(len(graph)):
print(f"Point {i+1}: {graph[i]}")
for j in graph:
plt.plot(graph)
plt.show()

You might also like