- Make sure python3 and pip3 are installed
- Run
pip3 install matplotlib numpy sympy
- Throw this
other gist
in a file (call it "
domath.py
" or something). - Run
python3 -i domath.py
to run the script and continue in an interactive shell. - You're done! (Well, done setting up, at least.)
- To actually do stuff with this, you can use the helper functions from that gist:
- The
plot_it
function will plot the graph of a function, taking these arguments:x_begin
andx_end
- The horizontal start and end values of your graph*funcs
- Zero or more functions to graph (use lambda expressions or references to function objects)step
(optional, named arg; default0.0001
) - The x distance between points on a graph. (Obviously, we can't plot the infinite number of points in a graph, so we choose a small step size to approximate it.)equalize_axes
(optional, named arg; defaultFalse
) - Whether to force the graph to have equal scales on the x- and y-axes (defaultFalse
)
- (Also, we've imported everything from the
math
module, so you can simply type stuff likesqrt()
andlog10()
.) - The
sci()
function formats a number in scientific notation. - The
factorize()
function finds a whole number's prime factors.- (This runs in linear time proportional to the largest prime factor. There could be room for optimization, but for now, avoid factorizing numbers with large prime factors.)
- There are also other helpers for trigonometry (sec, csc, cot).
- Here are some examples:
- To get the value
0.00000012
in scientific notation:
>>> sci(0.00000012)
'1.200000e-07'
- Here is an example of plotting two different functions, using lambdas and function references:
>>> plot_it(0, 10, sin, lambda x: x**2/20)
- Use the optional
equalize_axes
named argument toplot_it
to make the graph have equal x- and y-axis scales. Try this to see the difference:
>>> plot_it(0, 10, lambda x: x**2)
>>> plot_it(0, 10, lambda x: x**2, equalize_axes=True)
You can also use the other stuff I put in there for chemistry.