I have no idea how to start coding the following program in python 3: Write a program to draw a text-based graph of a mathematical function f(x). I don't expect an answer, just general guidelines as to what i need to do...
more detailed question: Write a program to draw a text-based graph of a mathematical function f(x). Use axis limits of -10 to 10, with only discrete points plotted. Use nested loops to scan through the entire area of the graph and wherever the (rounded) value of f(x) is equal to the y, output "o" (small letter Oh). Otherwise, output either the appropriate axis character or a space. Remember to import math to use some mathematical functions. To support entering of arbitrary functions, the user must enter a string at first. The Python eval function must then be invoked each time to compute the function value for different values of x.
ascii graphs; wow :-D turning the command line into a graphing calculator You can probably represent the entire graph as a big long string containing only the axes (made up of '|', '+', and '-' characters), spaces, and newline characters. Once you get a valid function of x from stdin, you can loop over x values from -10 to 10 (with a step of one), plotting circles. for x in xrange(-10, 11) : plot(x, f(x), 'o')
http://ideone.com/ezTVc This is how I approached the problem, but my solution has 3 problems: 1. Apart from constant inputs like `3`, the graphs are inverted. 2. Passing things like tan or 1/x yields ZeroDivisonError 3. It's in Python 2 :-D sorry about that. I hope it can guide you to your own working solution :-D
Alright, I've fixed the inverted problem: http://ideone.com/fW4Zc tan(x) and 1/x are still problematic though :(
I have actually managed to figure it out on my one... thanks for your help anyway :D
Join our real-time social learning platform and learn together with your friends!