Improving Mathcad Calculation Speed
|
There are various techniques you can use to speed up calculations in your Mathcad files. |
|
Reduce the Size of Your File |
|
Large files take longer to calculate. There are several ways you can reduce the size of your file. Under File > Properties, make sure that under the XML Options tab, that "Don't store large evaluated results" is checked, as below. This is the default option. |
|
Storing results means that reopened worksheets contain your last calculated results, however doing so makes the filesize very large. |
|
Saving Images in Your Files |
|
Another option to reduce file size is to check "No Images" on the XML Options tab. That means that math regions, graphs, and text won't be saved as images for viewing in other applications such as HTML or Word. |
|
You can also reduce the size of your images by choosing JPEG under "Region Image Rendering Options" then reducing the Image Quality. Note that too much reduction distorts your image. |
|
The way you save images can also make your Mathcad files very large. If you are pasting in an image, be sure to save the image in your original application to as few colors as possible, 256 colors rather than 24 bits if possible. Also crop the image as close as possible to the actual image. Even white space contains pixels of information. |
|
Other Ways to Control the Size of Your Files |
|
Large 3D graphs grow your files, so you may want to make short files and break up the graphs. Also calculations go faster in a smaller file, so keeping your files short helps. |
|
Another way to reduce file size is to avoid first displaying, then saving many large intermediate results. |
|
Improving Calculation Speed (from QuickSheet in Mathcad Techniques) |
|
Large vectors and matrices can be assigned and manipulated more quickly if you preallocate space in memory for the array. For example, your calculation speed increases if you first create a 0 entry at the last index of a matrix, telling the computer how big a space to set aside for filling with other values. Otherwise, a new, larger space must be created when an array grows, and the previously assigned entries must be copied into it. |
|
Increase the highlighted numbers to 500 and 800 to see how long each matrix takes to create. |
|
This strategy is equally important for assigning long vectors inside a program. |
|
Each matrix you create in the worksheet, such as Mslow and Mfast above, takes space in memory. While a worksheet is open, the memory stays in use, which means less virtual memory space for calculations, other storage, other open worksheets, and so on. If you create many large matrices for intermediate values in a calculation, you may run out of space before your calculation is complete. |
|
A better strategy is to perform intermediate array operations inside a program. Arrays are created only while the program is executed. Once the program finishes, any intermediate arrays are cleared from memory. This tactic speeds up your worksheet and lets you perform larger array calculations overall. |
|
Avoid Unnecessary Repetition of Operations |
|
As you develop a calculation, you may be focusing more on getting the right result than reducing repeated operations. For example, look at the expression below, which calculates the index of a data vector using a range expression rather than a value. |
|
This means that the expression |
|
is recalculated every time a new matrix entry is assigned, even though its value is constant. For large matrices, the additional operations can be significant. Instead, assign it to a value, then use the value in the range expression: |
|
produces the same result in less time. This idea is particularly important with matrix operations, such as matrix transposition and stacking and augmenting, which are time intensive. Note that stacking and augmenting prevents you from preallocating the matrix, and thus increases computation time. Consider these two methods for creating the same matrix: |
|
Working with column vectors until the last operation avoids transposing at each step, saving time. Avoiding the stack function allows you to preallocate the matrix. For these tiny arrays, the difference isn't noticeable, but for calculations with thousands of elements, these changes can speed up your work. |
|
Extract Elements Then Operate |
|
A similar strategy applies if you only need an operation performed on some elements of a matrix. It is quicker to extract the elements you need first, then apply operations, rather than operating on all matrix elements then extracting the meaningful values. For example, |
|
particularly for large matrices. |
|
Avoid Unnecessary Vectorization |
|
Mathcad's vectorize operator is a quick way to specify the element-wise meaning of an operation that performs differently with vectors or scalars. Many Mathcad operations vectorize automatically, as appropriate. However, vectorizing an operation that vectorizes itself is time consuming. Doing so removes the efficiencies that the built-in definitions apply and can increase matrix calculation time significantly.
So, for example, |
|
although it produces the same result. Be sure when you use vectorization on large problems that it's really necessary. Indexing elements and performing operations that would otherwise require vectorization can also be faster.
|
[PRINTER FRIENDLY VERSION]
|
|
|  |
 |
 |
|