Добавил:
kostikboritski@gmail.com Выполнение курсовых, РГР технических предметов Механического факультета. Так же чертежи по инженерной графике для МФ, УПП. Писать на почту. Дипломы по кафедре Вагоны Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
39
Добавлен:
12.08.2017
Размер:
2.3 Mб
Скачать

40 / Chapter 5 Range Variables and Arrays

Note Arrays created using the Matrix command on the Insert menu are limited to 600 elements. Use subscripted expressions, data import functions, or Data Tables to create larger arrays. The effective array size limit depends on the memory available on your computer, but is usually at least 1 million elements. For more information see online Help.

Changing the Size of a Vector or Matrix

You can change the size of a matrix by inserting and deleting rows and columns:

1.Click on one of the matrix elements to place it between the editing lines. Mathcad begins inserting or deleting with this element.

2.Choose Matrix from the Insert menu. Type the number of rows and/or columns you want to insert or delete. Then press either “Insert” or “Delete.” For example, to delete the column that holds the selected element in this example, you type 1 in the box next to “Columns,” 0 in the box next to “Rows,” and press “Delete.”

Iterative Calculations

Mathcad can do repeated or iterative calculations as easily as individual calculations by using a special variable called a range variable.

Range variables take on a range of values, such as all the integers from 0 to 10. Whenever a range variable appears in a Mathcad equation, Mathcad calculates the equation not just once, but once for each value of the range variable.

Creating a Range Variable

To compute equations for a range of values, first create a range variable. In the problem below, for example, you can compute results for a range of values of t from 10 to 20 in steps of 1.

To do so:

1. First, type t:10. Click on the 10 in the equation t:=10.

2.Type,11. The next number in the range is 11, and the step size is 1.

3. Type [;] for the range variable operator or click

 

on the

Matrix toolbar, and then type the last number, 20. The last number in the range is 20. Mathcad shows the range variable operator as a pair of dots.

Iterative Calculations / 41

4.Now click outside the equation for t. Mathcad begins to compute with t defined as a range variable. Since t now takes on eleven different values, there must be eleven different results, which are displayed in an output table as shown.

You can use one or more range variables to fill up the elements of an array. If you use two range variables in an equation, for example, Mathcad runs through each value of

each range variable. This is useful for defining matrices. For example, to define a 5 × 5 matrix whose i,jth element is i + j, enter the equations shown in Figure 5-1.

Enter the subscript operator by clicking on the Matrix toolbar or by pressing the [[] key.

The xi,j equation is evaluated for each value of each range variable, for a total of 25

evaluations. The result is the matrix shown at the bottom of Figure 5-1, with 5 rows and 5 columns. The element in the ith row and jth column of this matrix is i + j.

Figure 5-1: Defining a matrix using range variables.

Note When used to define an array element, an array subscript can only take on integer values.

For more details on range variables, see “Range Variables” on page 84.

Entering a Matrix as a Data Table

You can use a data table to get the convenience of a spreadsheet-like interface for entering data:

1.Click in a blank spot in your worksheet and choose Data > Table from the Insert menu.

42/ Chapter 5 Range Variables and Arrays

2.Enter the name of the Mathcad variable to which the data will be assigned in the placeholder.

3.Click in the data table and enter numbers into the cells. Each row must have the same number of columns. If you do not enter a number into a cell, Mathcad inserts 0.

Figure 5-2 shows two data tables. Notice that when you create a data table, you’re actually assigning elements to an array that has the name of the variable you assigned.

Figure 5-2: Using data tables to create arrays of data.

When you click the table, you can edit the values in it using the scroll bars. To resize the table, move the cursor to one of the handles along the sides of the region so that the cursor changes to a double-headed arrow. Press and hold down the mouse button and drag the cursor to change the table’s dimensions.

Note A data table can be used to import from a data source or another application containing data. Right-click on the top-left corner and choose Import from the menu. The imported data can be edited in Mathcad as described above.

Tip You can copy data from a data table as follows: first select the data, then right-click on the data table and choose Copy from the menu. You can paste a single number into the table by rightclicking a cell and choosing Paste from the menu. Choosing Paste Table from the menu overwrites the entire table.

Соседние файлы в папке doc