Each trace on a graph depends on a range variable, and Mathcad graphs one point for each value in the range variable. As mentioned in the previous section, however, Mathcad automatically generates a default range for the dependent variable of an expression you type in the y-axis and creates the graph over it if you do not explicitly define a range variable.

If you want to specify exactly what range of values the range variable has, you can define a range variable in your worksheet. This method is described in the following sections.

Graphing a function

To graph a function over a range, as shown in Figure 20-2, do the following:

• Define a range variable, such as x, that ranges over the values you want to graph. (The range variable need not be called x; you can use any valid Mathcad name.)  for instructions on defining a range variable.

• Type the expression you want to plot in the middle placeholder of the y-axis andtype x in the middle placeholder of the x-axis.

• Click anywhere outside the graph region to see the plot.

Graphing an expression against a range variable.

You can also define a function fix) and place it in the middle placeholder of the y-axis. This is particularly useful when the expression you want to plot becomes large and unwieldy. The second graph in Figure 20-2, above, shows the same plot as the first graph in the figure, except that it is made with a function definition

Using functions for polar plots

By creatively using the tools presented in this chapter, you can plot a wide variety of closed curves. The example in Figure 20-3 illustrates how to transform polar into rectangular coordinates. This technique lets you create polar plots, or even paths in the complex plane. In Figure 20-3, the equation for the cardioid in polar coordinates is given by r(8). The equations for x(8) and y(8) are the usual transformation from polar to rectangular coordinates. See , “Polar Plots,” for a description of Mathcad’s built-in polar plotting capabilities.

Two functions computed independently.

Graphing a vector

To graph the elements of a vector, you need to use the vector subscript operator to specify which elements to plot. A graph of a vector is shown in Figure 20-4. To create this graph, do the following:

• Define a range variable i that references the subscript of each element you want to plot.

•Define a vector Yi’ Use the left bracket key, [, to create the subscript.

• Press @ to create an empty plot region.

• Place Yi in the middle placeholder of the vertical axis and i in the middle placeholder of the horizontal axis.

• Click anywhere outside the graph region to see the plot.

A graph created using these steps is shown in Figure 20-4.

Graphing a vector.

Subscripts must be non-negative integers (or integers greater than or equal to ORIGIN, if ORIGIN:;cO.) This means that the x-axis variable used in a graph like Figure 20-4 can run through whole-number values only. If you want to graph fractional or negative values on the x-axis, graph a function as in Figure 20-2, or graph two vectors as described in the next section.

If you have a handful of data points that don’t have a convenient functional relationship as in Figure 20-4 but there are too few of them for you to use data files, you might want to use an input table to create a vector. For more information, see “Entering data manually” on page 429.

Graphing one vector against another

To graph all the elements of one vector against all the elements in another, enter the names of the vectors in the x- and y-axis placeholders on the graph. For example, to create the first graph shown in Figure 20-5:

• Define x and Y as shown in the figure.

• Press @ to create an empty graph region.

• Place y in the middle placeholder of the y-axis and x in the middle placeholder of the x-axis.

• Click anywhere outside the graph region to see the plot.

Mathcad plots all the elements in the vector x against the elements in the vector y. If the vectors are not the same length, Mathcad will plot the number of elements in the shorter vector.

In some cases, you may prefer to explicitly tell Mathcad which elements of the vectors to plot. This is useful when you want to only plot some of elements. To plot certain elements as opposed to all of them, you must define a range variable and use it as a subscript on the vectors. The subscript references the elements to graph. A graph produced using this method is shown in Figure 20-1. The vectors do not need to be the same length. The only requirements are:

• The two vector must share the same subscript. For example, you cannot plot xi against Yj because i andj are not the same subscript.
• Each value of the subscript must correspond to an element in each vector. For example, if x has only two elements and y has eight elements, and the range variable goes from 0 through 7, you will get an error
• Press @ to create an empty graph region.
• Place vYt in the middle placeholder of the y-axis and vXt in the middle placeholder of the x-axis.
• Click anywhere outside the graph region to see the plot.

Graphing two vectors.

Although the x vector in Figure 20-5 is a list of evenly spaced values, this need not be the case. Only the i values are required to be evenly spaced integers. No such restriction exists for the Xi .  his allows you to plot something besides integers on the x-axis while still satisfying the requirement for integers as subscripts.

In Figure 20-5, the Yi came directly from the xi’ Other applications might compute x and Y independently from a third variable. As long as the two vectors use the same range variable, you can graph them on the same graph. Figure 20-6 shows a polar graph in which both x and y depend on the variables rand 9. Figure 20-6 uses vectors to do what was done with functions in Figure 20-3.

Two vectors computed independently.