TextEdit Icon

Plot an Expression

To plot any function of x, open the inspector window (using the Plot Inspector menu command or tool bar icon). Click on the f(x) tab and proceed as follows:

  1. Enter any function of x using operators +, -, *, /, and ^ for plus, minus, product, divide, and power. The only variable allowed is x (although y can also be used in k(x,y) expressions for data transformations) and normal operator precedence is used (^ over (* and /) over (+ and -)).
  2. The function can include special functions:
    • sin(x), cos(x), tan(x) - trig functions with argument in radians
    • asin(x), acos(x), atan(x) - inverse trig functions with result in radians
    • sinh(x), cosh(x), tanh(x) - hyperbolic trig functions
    • erf(x), erfc(x) - error function and its complement
    • exp(x) - exponential
    • log(x), log10() - natural log and log base 10
    • sqrt(x) - square root
    • abs(x) - absolute value
    • int(x) - integer part
    • mod(x,y) - returns remainder of x/y and allows non-integers. For remainder after integer divsion (e.g., "x % y" in C++), use int(mod(x,y)) where y is an integer.
    • rand(x) - a random number between 0 and x.
    • sign(x) - 1 if x is positive or 0 if it is negative
    • sgn(x) - -1 if x <0, 0 if x=0, and +1 if x>0
    • ramp(A,x) - 0 if x< 0, Ax if 0<x<1, A if x>1
    • cosramp(A,x) - 0 if x< 0, (A/2)(1-cos(πx)) if 0<x<1, A if x>1
    • box(A,x) - 0 if x< 0, A if 0<x<1, 0 if x>1
    • sinbox(A,x) - 0 if x< 0, A sin(πx) if 0<x<1, 0 if x>1
    • tri(x) - 1-|x| for -1 < x < 1, 0 otherwise
    Hint: to visualize any function, plot it as the expression.
  3. Enter the range of x values to plot in x minimum and x maximum
  4. Enter the number of Points to use between the minimum and maximum x values.
  5. Decide if the points should be equally spaced on linear or log axes. The Use Log Spacing option is preferred when plotting the expression on a log scale along the x axis. When using log spacing, both x minimum and x maximum must be greater than zero.
  6. Click the Plot button.

For an example, try the following function:

  1. Create a new plot, open the Plot Inspector, and click on the f(x) tab
  2. Enter the function x*cos(2*x)
  3. Set x minimum to 0, x maximum to 10, and Points to 200
  4. Click the Plot button

Hint: to plot y = constant (or a horizontal line), which is independent of x, just enter the constant.

Hint: to plot x = constant (or a vertical line), which is not a function, set x minimum and x maximum to the same value. The entered expression will be ignored and the vertical line will be between the current minimum and maximum along the y axis.