# Sketching graphs

How are graphs plotted or sketched?

If you have a graph plotting software for example mathematica or matlab, or you want to see what the graph of $e^{2x}$ looks like, how do you plot/sketch such a graph?

If you proceed by using a finite number of points, and "extrapolating" and "interpolating", then how do you know that that method is reliable? There are infinitely many smooth(or non-smooth) graphs that can be drawn through a finite number of points.

-

1
Are you asking how to use the software or what the software does? The first question seems off-topic. The answer to the second question is that convergence of PL approximations is a consequence of continuity, and we generally assume that the functions we're interested in are continuous. (This may sometimes be false, e.g. near a singularity, and even then one has to worry about numerical instability when solving differential equations, for example. But for plotting a function like e^{2x} these issues don't arise.) – Qiaochu Yuan Jan 20 '11 at 23:44
what the software does, and why hand sketched graphs are reliable. – picakhu Jan 20 '11 at 23:48

4
Not all software packages check to see that their sketches are reliable. Sometimes the sketches generated by software can be very bad -- frequently it's a poor choice of scale, or poor perspective, or the software doesn't know where the "interesting stuff" is happening. Sometimes the software doesn't notice peculiarities of the function -- vertical asymptotes can cause trouble. "Good software" tends to use adaptive methods that find reasonable bounds on things like $|f(x)|$ and $|f'(x)|$ before attempting to sketch, but it really depends. – Ryan Budney Jan 20 '11 at 23:58
This is not a simple question. Even advanced plotting software like mathematica has its issues with some nasty oscillating function graphs so there is no method yet that always works. However if your function is smooth enough you can make a reasonable interpolation with polynoms and use this to draw the function. – Listing Jan 21 '11 at 0:03

## 1 Answer

Basically (keyword: "basically"), it works like this:

````BEGIN
    DECLARE x
    SET x TO x1
    WHILE x IS LESS THAN TO x2
        DRAW LINE BETWEEN f(x) and f(x-step)   // "linear interpolation"
        INCREASE x BY step
    END WHILE
END
````

Where step is some small number... Something like 0.01, depending on how fast you want it. $step = \lim_{x\to 0^+}$ would be "perfectly smooth", but we don't have the resources for such measures, so we're stuck with anything between $10^{50}$ and $10^{-50}$.

They won't be "infinitely smooth". That would require infinite amounts of RAM and CPU. It only has to "look" smooth. It's only limited by your RAM/CPU, time (unless you feel like waiting a few trillion years), and most importantly, your screen resolution.

More complex plotters can determine the vertical asymptotes, but I don't need to get into that.

-

I understand this, but when is it reliable? – picakhu Jan 21 '11 at 3:41
See Ryan's comment above - a good graphing package will attempt to heuristically estimate the modulus of continuity. This is not possible (non-recursive) in the black-box model, but if the function is given explicitly enough, then by bounding the derivative you can bound the modulus of continuity and so draw a meaningful graph. – Yuval Filmus Jan 21 '11 at 4:42
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 6, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9334626197814941, "perplexity_flag": "middle"}