Plotting and Functions Tutorial
Functions and Plotting Tutorial
A live version of this calculation is available at EngineeringPaper.xyz.
Functions and plotting are related in EngineeringPaper.xyz since they both use a similar notation. In EngineeringPaper.xyz, any variable may be called as a function. Below, we define two variables that we will later use as functions:
$$ y_{1}=c\cdot x $$
$$ y_{2}=x^{2} $$
To call a variable as a function, use the following notation:
$$ y_{1}\left(x=2\right)= 2 \cdot c $$
$$ y_{1}\left(x=2,\ c=4\right)= 8 $$
$$ y_{2}\left(x=2\right)= 4 $$
Note that the parameters can be passed to the function in any order. Functions can also be used in more complex expressions as shown by the following example:
$$ y_{1}\left(x=3,\ c=4\right)\cdot y_{2}\left(x=30\right)\cdot10= 1.08\times 10^{5} $$
To create a plot, call a variable as a function and use a range for a parameter instead of a specific value. For example y_2(-10<=x<=10)= will create a plot of a parabola for values of x from -10 to 10 inclusive:
A plot may be created by typing the y_2(-10<=x<=10)= query statement directly into a math field and it will automatically convert the current math cell into a plot cell. Alternatively, a new plot cell may be inserted into the sheet using the insert plot cell button:
Multiple functions can be plotted simultaneously, as shown above, by adding additional fields below the plot by clicking the plus button (or by using the Enter key).
If you would like to copy the raw plot data directly into Excel, Google Sheets, or Numbers, use the “Copy Data” button below the plot to copy the data to the clipboard and then the data can be pasted directly into your spreadsheet software using Control-V or Command-V.
A log scale can be used for the x and the y axes by clicking the “log x” and “log y” toggles below the plot as shown below:
Note that range syntax supports both the < and <= symbols (the less than or equal to symbol is obtained by simply typing < followed by =, the on screen keyboard may also be used). The < symbol is used when an open limit is required, such as in the above example where 0 is undefined for a log-log plot. An open limit takes the range close to the limit without including the limit value itself. This is useful in cases, such as this one, where the limit value is undefined or generates an error.
Just like anywhere else in EngineeringPaper.xyz, units are fully supported when using functions and plots. The following plot adds units to the previous example:
Note that, since the two resulting curves have different units for their y-axis values, two different y-axes are used. EngineeringPaper.xyz will automatically generate up to four different y-axes for cases where the y-values have different units. However, all of the plotted functions need to have compatible units for the x-axis values, as in the above example.
By default, EngineeringPaper.xyz uses 51 points for a plot. Occasionally, more points are needed to represent a function smoothly as in the following example:
$$ y_{3}=\sin\left(t\right) $$
To add more points to a curve, simply append the function with “with 500 points” to get 500 points, for example. This is easier to show by example. Below is the same plot repeated with 500 points. This feature is especially useful when combined with the “Copy Data” button to get a specific number of points for use in spreadsheet software.
Scatter plotting and parametric plotting are also supported. For details, see the scatter plotting and the parametric plotting tutorials.