Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views1 page

Plotting and Classes

This document defines a Point2D class that calculates the value of the function f(x) = e^(-|x|) * cos(2 * PI * x) for a given x value. It then prompts the user for x values, calculates the function for each, stores the results in a list, and plots the points on a graph.

Uploaded by

Leonardo Peña
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Plotting and Classes

This document defines a Point2D class that calculates the value of the function f(x) = e^(-|x|) * cos(2 * PI * x) for a given x value. It then prompts the user for x values, calculates the function for each, stores the results in a list, and plots the points on a graph.

Uploaded by

Leonardo Peña
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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