Graphing with HC

Graphing support was introduced with version 0.6 of HC, in 0.7, I added 3D graph support, in 0.9.2, I added support for multiple functions displayed on one graph, and in 2.0, I added support for parametric graphing and slope fields.
HC uses the plplot library to generate the graphs, and uses the PNG driver on Linux et. al, or wingcc if on Windows.

This is now supported both in the CLI and GUI versions.

Example usage for 2D graphs
Usage is simple; fire up your copy of hc and type something according to the following syntax:
graph(expr[,xmin,xmax,ymin,ymax])
(xmin, etc., are optional, the last will be used if none will be entered)
and of course replace expr with the expression you want to use for your graph (for example x^2), and xmin, xmax, ymin and ymax with the coordinates of the "window" of the graph.
If on Linux/*nix, you will then be prompted to enter a filename to save the graph to; enter something ending in .png, for example graph.png.
Afterwards, simply open the newly generated graph.png with your favorite image viewer.
If on Windows, the graph should be displayed right away, using the wingcc driver.

Example generated 2D graph
Example 2D graph

As you can see, hc also properly handles discontinuities.



If you want to graph multiple functions in one graph, use the gmul() function, which takes an arbitrary number of function expressions as its argument.
For example, to graph the functions x, x^2, x^3 and x^4 on the same graph, you would use:
gmul(x,x^2,x^3,x^4)
(note : to set xmin, xmax, ymin, ymax, call graph() first with one of the functions and the corresponding xmin, etc.)
Which would show:
Example multiple functions graph

Example usage for 3D graphs
Usage is very similar to 2D graphs; only you have to use the graph3() function, instead of graph().
Not surprisingly, the syntax for this function is:
graph3(expr[,xmin,xmax,ymin,ymax,zmin,zmax])
(xmin, etc., are again optional)
Again, replace expr with a valid expression you want to use for your graph (for example (x^3*y-y^3*x)/390 (you could also use implied multiplication from version 0.9.3)), and xmin, xmax, ymin, ymax, zmin and zmax with the appropriate coordinates.
Example generated 3D graph
Example 3D graph

Example usage for Parametric equations
The corresponding function is:
graphpeq(expr_x,expr_y[,tmin,tmax,xmin,xmax,ymin,ymax])
(tmin,etc., are again optional)
Similarly as for the previous functions, just replace expr_x and expr_y with valid expressions for x and y respectively in terms of t, and if you want to, you can specify the tmin,tmax, etc., intervals.
Example generated parametric equation graph
graphpeq(sin(t),cos(t),0,2pi,-1,1,-1,1)
Example parametric graph

Example usage for slope fields
The corresponding function is:
slpfld(expr[,xmin,xmax,ymin,ymax])
(xmin, xmax, etc. are optional)
The principle stays the same as for the other functions -- replace expr with a valid expression in terms of x and y, and xmin, etc., with appropriate coordinates if you want.
Example generated slope field
slpfld(x+y)
Example slope field graph

Back to HC's main page