next up previous contents
Next: Displaying your graphs Up: Graphs Previous: Graph Objects   Contents

Adding functions to your graph object

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 $ y = x^2$ 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 $ -3$ and 3. You want to graph x$ \wedge$2 + $b x + $c. Now if $ b$ or $ c$ is negative, you will obtain an expression like $ x^2 + {-3}x + {-2}$, 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 $ x = 3$ will be clearly shown with an open circle at $ (3,3)$ and a filled circle at $ (3, -1)$.


next up previous contents
Next: Displaying your graphs Up: Graphs Previous: Graph Objects   Contents
Thomas R. Shemanske 2002-03-05