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

Working with Arrays / 47

Figure 5-7: Copying and pasting results from an output table. Column numbers run across the top row, while row numbers run down the left edge. The highlighted numbers are selected to be copied. Type y:, then paste the copied results from the output table.

Tip When you display an array as an output table, you can export data directly from the table. Rightclick on the output table, choose Export from the menu, and enter the name of the file, the format, and the columns and rows to export.

Working with Arrays

There are many operators and functions designed for use with vectors and matrices; see “Matrix Toolbar and Operators” and “Vector and Matrix Functions” in online Help. This section highlights the vectorize operator, which permits efficient parallel calculations on the elements of arrays. You can also display the values of an array graphically or export them to a data file or another application.

Performing Calculations in Parallel

Any calculation Mathcad can perform with single values, it can also perform with vectors or matrices of values. There are two ways to do this:

Iterate over each element using range variables. See “Iterative Calculations” on page 40.

Use the vectorize operator to perform the same operation on each element of a vector or matrix individually.

48 / Chapter 5 Range Variables and Arrays

Mathematical notation often shows repeated operations with subscripts. For example, to define a matrix P by multiplying corresponding elements of the matrices M and N, you write:

Pi, j = Mi, j Ni, j

Note that this is not matrix multiplication, but multiplication element by element. It is possible to perform this operation in Mathcad using subscripts, but it is faster to perform the same operation with a vectorized equation. The notation is also more compact.

To apply the vectorize operator to an expression like M N :

1.Select the expression by clicking inside it and pressing [Space] until the right-hand side is surrounded by the editing lines.

2.Click on the Matrix toolbar to apply the vectorize operator. Mathcad puts an arrow over the top of the selected expression.

For example, suppose you want to apply the quadratic formula to three vectors containing coefficients a, b, and c. Figure 5-8 shows how to use the vectorize operator.

The vectorize operator, appearing as an arrow above the quadratic formula in

Figure 5-8, is essential in this calculation. Without it, Mathcad would interpret a c as a vector dot product and also flag the square root of a vector as illegal. But with the vectorize operator, both a c and the square root are performed element by element.

Figure 5-8: Quadratic formula with vectors and the vectorize operator. First set up the three coefficients. Then compute a root. The result should be zero.

Note While vectorization is faster than element-by-element operations for those operations which require it, it will be slower than natively vectorized operations. Many operations are already performed on an element-by-element basis, such as the addition of two arrays. For such operations, adding an unnecessary vectorization operator will give the same result, but much more slowly.

Working with Arrays / 49

Graphical Display of Arrays

In addition to looking at the actual numbers making up an array, you can also see a graphical representation of those same numbers. There are several ways to do this:

For an arbitrary array, you can use the various three-dimensional plot types discussed in Chapter 12, “3D Plots.”

For an array of integers between 0 and 255, you can look at a grayscale image by choosing Picture from the Insert menu and entering the array’s name in the placeholder.

For three arrays of integers between 0 and 255 representing the red, green, and blue components of an image, choose Picture from the Insert menu and enter the arrays’ names, separated by commas, in the placeholder.

See Chapter 10, “Inserting Graphics and Other Objects,” for more on viewing a matrix (or three matrices, in the case of a color image) in the picture operator.

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