Python Forum
How To Export XY Coordinates Of A Function To CSV
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Export XY Coordinates Of A Function To CSV
#1
How can I output the X and Y coordinates of a mathematical function to a CSV output? As a very basic example, if f(x)=x^2, then how could I generate a CSV file or list with coordinates of this mathematical function for a range 0>x>100? I am able to graph mathematical functions, but have not figured out how to extract the coordinate information.

Thanks!
Reply
#2
Are you working with a toolkit, or are you just wanting to roll it yourself? It could be as simple as just creating your domain and then evaluating at every point.

Then print both the point and the function's value at that point.

def square(num):
    return num ** 2

print("X,Y")
domain = range(100)
for x in domain:
    print(f"{x},{square(x)}")
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020