So now that you have an object on which to draw your graph(s), we should specify a function. Now as the most trivial of examples, let us suppose we want to draw the graph of on the axes we have just defined. Nothing could be simpler:
$f = ``x^2 for x in [$xmin, $xmin] using color:blue and weight:2''; add_functions($graph_object, $f);
Exception to the Rule 2: Note that in this construction the variable x is not prefaced by a $.
Usually, one has somewhat more interesting examples to graph. Suppose that $b and $c are real numbers between and 3. You want to graph x2 + $b x + $c. Now if or is negative, you will obtain an expression like , less than optimal for parsing. So one uses the FEQ function (Format EQuations) and writes
$f = FEQ(``x^2 + ${b} * x + ${c} for x in [$xmin, $xmin] using color:blue and weight:2'');which will return the string (assuming the values of $b, $c above)
$f = ``x^2 - 3 * x - 2 for x in [$xmin, $xmin] using color:blue and weight:2''In particular, FEQ will take care of adjacent +- or -+ or - signs with no prompting.
Certainly, you can draw multiple functions with possible different domains on the same graph object. As a simple example, let's draw a piecewise linear function.
$f1 = ``-2 * x - 6 for x in [$xmin, -2) using color:blue and weight:2''); $f2 = ``x for x in [-2, 3) using color:blue and weight:2''); $f3 = ``x - 4 for x in [3, $xmax] using color:blue and weight:2''); add_functions($graph_object, $f1, $f2, $f3);
The discontinuity at will be clearly shown with an open circle at and a filled circle at .