RANGE VARIABLES AND TABLES

A range variable allows you to perform a calculation over a range of conditions. For example, given the equation y = x + 7, find the value of y when x is equal to the range 3 to 10. In such an equation, the range variable 'x' MUST appear both as a subscript AND an argument of 'y'.

<-- First define the range by entering the keystrokes x:3,4;10 To assign a range to variable x, first define the first number of the range, enter a comma and type the next number of the range. The difference between your first and second entry defines the step. Enter a semicolon (which appears on screen as two consecutive dots), finally enter the last number in the range.

To define the range of values assumed by 'y' using the range variable 'x', y must be defined with x as a subscript. The variable 'x' must be a variable within the equation defining 'y' as indicated below. The subscript is entered using the '[' key. DO NOT CONFUSE THIS VECTOR SUBSCRIPT WITH A LITERAL SUBSCRIPT. A literal subscript is entered using the period '.' key.

<-- A literal subscript will result in an error

<-- Subscript must be a vector subscript.

<-- Now simply enter y= and all values of y will be displayed in a table. Note the first three entries, y_{0}, y_{1} and y_{2} are equal to zero. This is because the subscript of y takes on the initial value of x as previously defined. Also note that the first element of this table (vector) is zero. This is default for MathCAD. If you desire the first element to be element one, you can change this under the menu item Math/Options/Array Origin.

If you would like to eliminate the null entries from the the resulting vector, create an equation for the subscript that will set the first entry to zero or one as appropriate. An example follows.

<-- Enter the subscript as x-3. This sets the first subscript to zero.

<-- The first value of the equation is now assigned to y_{0} rather than y_{2}

A range variable need not be an integer. However, a subscript MUST be an integer. There are a couple of ways to handle this.^{ } First, since the range variable is essentially an arithmetic series, one should be able to write an equation for the subscript to convert the noninteger value to an integer. For example, lets look at the equation a=i^{2}.

<-- The range variable is defined as a noninteger series

<-- This equation generates an error because the subscript is noninteger. Click on the equation to see the error.

<-- The subscript is defined in terms of i such that it is an integer value. To do so, simply multiply the subscript by 10. This forces the subscript to be an integer. We also subtract 3 from the subscript so the first calculation is displayed in the zero^{th} element of the vector.

<-- Display the resulting vector as normal

A second way to handle this situation is to define a range variable in terms of integer values as normal. Then define the data in a vector. For example:

<-- There are 10 values in the range of i=0.3,0.4 .. 1.2. So instead of defining i with decimal values, define it with integer values from 0 to 9.

<-- Define each element of the vector j_{i}. To do so, enter the keystrokes j [ i : 0.1 , 0.2 , ........ , 1.0. The comma entered after the first entry (0.1) will convert the variable to a vector entry. Obviously, this is only practical for rather small amounts of data. Later in the course, we will investigate the use of Read/Write statements to read this data from an ASCII file as might be generated by a spreadsheet or a data acquisition system.

<-- Write the equation with both variables using the subscript i and...

<-- ...Display as usual

Range variables can also be used as a subscript for multiple variables within an equation to develop a matrix of solutions. For example, determine a matrix of solutions for the equation k = i^{2} + j^{2} for values of i from 1 to 10 and values of j from 2 to 20 with a step value of 2.

<-- Define the two range variables

<-- Note that if you display the matrix k without modifying the subscripts, you will get the matrix shown below. Notice that every other column is a column of null values and that the first column and first row are also null values. This would result in a significant problem if your range variables were large numbers with a large step value.

<-- Write the equation with the subscripts applied to the dependent variable. Note the first subscript is defined such that the first row of the matrix is column zero. The second subscript is based on range variable j. The subscript is multiplied by 1/2 to increment the column numbers by one instead of two and indexed by -1 to set the first column of the matrix to column zero.

<-- Now when kk is displayed, it will

display as a matrix of solutions

without the null values as shown

in the matrix above.

Units may be used with range variables, but not within the variable itself. For example, velocity is defined as distance divided by time. Given a distance of one to two feet and a time of 1 to 10 sec, determine velocity for each pairing of distance and time.

<-- Simply enter the unit within the range.

<-- However, the subscripts comprising the range must be

unitless. As such, you must divide the subscript by the

unit so as to eliminate the unit

The resulting unit will display with the matrix or table of solutions.

An easier alternative and [in my opinion] preferred way to write this is to include the unit inside the equation rather than the range variable.

__Summary__

a) Range variables can have units, subscripts cannot.

b) Range Variables can be decimal numbers, subscripts cannot.

c) To modify a subscript so it is an integer value with a step of one:

1) Multiply through by some value such that the range of the subscript is integer.

2) Multiply through by some value such that the range of the subscript has a step value of one.

3) Subtract an appropriate value from the range of the subscript such that the starting value of the subscript

is equal to the value of the array ORIGIN as set in the Worksheet Options dialogue.