Skip to content
AgileLogics

Graphing Calculator

Parses a mathematical expression in x (e.g. sin(x) + x^2/10) using a small built-in expression evaluator, and plots it as a downloadable graph over a chosen X range.

How it works

Enter an expression in x, set the X range, and click Generate.

How do I graph a function online?

Type an expression in terms of x, such as sin(x) + x^2/10, set the X min and X max of the range you want to see, and click Generate. The calculator evaluates the expression at 401 evenly spaced points across that range, scales the vertical axis to fit the results, and draws the curve as a 480 × 360 PNG you can download as graph.png.

You don't write y = in front; the box takes only the right-hand side. Typing y = x^2 gives an "Unexpected character" error at the =.

Supported syntax

Kind What you can use
Variable x (upper or lower case)
Numbers 3, 0.25, .5, 1e-3, 6.02E23
Constants pi (3.14159...), e (2.71828...)
Operators +, -, *, /, ^ for powers, parentheses
Trig (radians) sin, cos, tan, asin, acos, atan, atan2(a, b)
Roots and powers sqrt, cbrt, exp, pow(a, b)
Logarithms log (natural), log10, log2
Rounding and sign abs, floor, ceil, round, sign
Comparison min(a, b, ...), max(a, b, ...)

These names behave like the functions of the same name in JavaScript's Math object, because that's what they call.

Operator rules worth knowing

The parser follows normal mathematical precedence, with a few points that trip people up:

  1. Powers bind tighter than a leading minus: -x^2 is the upside-down parabola −(x²), and -2^2 is −4.
  2. Powers group from the right: 2^3^2 means 2^(3^2) = 2^9 = 512, not 8^2.
  3. A negative exponent needs no brackets: x^-1 works.
  4. Multiplication is never implied. Write 2*x, x*(x+1) and 3*pi.
  5. A leading + isn't accepted, and neither are ** or %.

Worked example

With the default range of −10 to 10, sin(x) + x^2/10 produces a parabola with a gentle wobble. A few of the values the calculator samples:

x sin(x) + x²/10
−10 10.544
−5 3.459
−2 −0.509
0 0.000
2 1.309
5 1.541
10 9.456

The curve isn't symmetric, because the sine term pushes the left side up and the right side down. That's easy to miss in a table and obvious in the plot.

Reading the graph

The image shows a light grey frame, the x-axis and y-axis drawn wherever zero falls inside the visible range, and the function as a blue line. There are no tick marks or numbers on the axes. You know the horizontal range because you set it; the vertical range normally runs from the lowest to the highest value found, plus 10% padding above and below. If the function is constant, the range is that value ± 1 before padding. The exception is a function with a few extreme values, such as tan(x) near its asymptotes: when the full spread is more than ten times the spread of the middle 90% of values, the range is fitted to that middle band instead (with some extra room) and the curve runs off the top and bottom of the frame where it shoots away.

So the graph is best for seeing the shape of a function: where it crosses zero, where it peaks, how it grows. For exact values at specific points, use the scientific calculator. To solve for where a function equals something, the algebra solver is the better tool.

Gaps, asymptotes and errors

Any point where the result isn't a finite number (division by zero, sqrt of a negative, log of zero) is skipped, and the line breaks there. sqrt(x) on −10 to 10 is drawn only for x ≥ 0.

Asymptotes are handled too. With tan(x) or 1/x the samples on either side of an asymptote are huge and of opposite sign. The calculator detects that jump (the neighbouring values sit on opposite sides of the visible range, or a value checked between them shoots off-screen) and lifts the pen instead of joining them with a near-vertical line, so each branch is drawn separately. Thanks to the fitted vertical range described above, the rest of the curve stays readable instead of being squashed flat by the extremes.

If you want a specific vertical window, clip the output yourself: max(-10, min(10, tan(x))) caps the values at ±10. Very fast oscillations, like sin(100*x) over a wide range, can't be drawn faithfully with 401 samples; narrow the X range to see their shape.

Message (after "Invalid expression:" where applicable) Cause
Unknown function "ln" Not in the supported list; use log
Unexpected token "x" Missing *, as in 2x
Expected ")" but found "end of expression" Unbalanced brackets
X min must be less than X max. Range reversed or equal
X min and X max must be numbers... Text such as abc in an X field
That expression did not produce any finite values over this X range. e.g. sqrt(x) with X max below 0

An empty X field uses its default, −10 for X min and 10 for X max, so clearing a box resets it rather than turning it into 0.

Privacy

The parser and the drawing both run in your browser on a canvas; nothing is sent to a server. Since the function names mirror JavaScript's own, the JavaScript cheat sheet is a handy companion if you later move a formula into code.

Last updated

Frequently asked questions

Is my expression evaluated with JavaScript eval()?
No. Expressions go through a small hand-written parser that only understands numbers, x, pi, e, a fixed list of math functions and the operators + - * / ^. Anything else, such as alert(1), is rejected with an error and never executed.
Why does 2x give an error?
Multiplication must be written out. Type 2*x, not 2x, and 3*sin(x), not 3sin(x). Without the asterisk you'll see Invalid expression: Unexpected token "x".
Are trig functions in degrees or radians?
Radians, as in most programming languages. To work in degrees, convert inside the function: sin(x*pi/180) treats x as degrees, so set X min and X max to something like 0 and 360.
How do I plot the natural log?
Use log(x). In this calculator log is the natural logarithm (base e); ln isn't recognised. For base 10 use log10(x), and for base 2 use log2(x).
Can I plot more than one function at once?
No, one expression per graph. You can still compare two curves as a single expression, for example max(sin(x), cos(x)), or generate each graph separately with the same X range.