cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

## Matrix preallocation of functions  1-Newbie

## Matrix preallocation of functions

I'm handling matrices that contain large numbers of functions that are symbolically evaluated, and then used to create differential equations for a solver such as Radau to solve.

I want to preallocate the matrices in order to speed up the rate that my code executes at, since there are a lot of these functions (about 700).

I understand how to preallocate normal matrices of actual number values via this method, where M is a 500 X 1 matrix:

M[500,1:=0

...and then you would define M via a file upload, or manual entering of data, via calculations from other matrices, or from a programming loop.

But...if I want a matrix of functions, how do I do it?

If M is a function of x for example, and I enter this into Matcad:

M(x)[500,1:=0

then Mathcad makes the M red, and says "a name is required here." Also, even if I use an 'x' instead of a zero to define the preallocation, it still gives me the same warning.

Does anyone know how or if matrices of functions can be preallocated?

1 ACCEPTED SOLUTION

Accepted Solutions  19-Tanzanite
(To:ptc-3031221)
 Normally you do this by specifying a value of zero to the last value of the matrix (extreme right, bottom cell).

You can enter anything into the last matrix element, it doesn't have to be zero. In the rather trivial example I showed the last element is 2, and I allocated that first. If you delete the lines assigning functions to M0 and M1 you will see you have a three element vector, with the first two elements set to zero.

Preallocation actually makes much less difference in the latest version of Mathcad. It used to make a huge difference, but not any more.

4 REPLIES 4  19-Tanzanite
(To:ptc-3031221)

It's not 100% clear to me what you are trying to do, but does this help?   1-Newbie
(To:RichardJ)

No, that's not quite what I'm looking for. By preallocate, I mean that if you are working with large matrices, you can speed up your computations if you tell Mathcad ahead of time how large the matrix is going to be. Normally you do this by specifying a value of zero to the last value of the matrix (extreme right, bottom cell). If you don't do this, Mathcad expands the matrix size of the result by one cell every time it repeats a calc, and expands the RAM allocated to storing that matrix as well. This extra activity slows it down significantly when the matrices are large. I have some matrices of functions that are large enough that I would like to preallocate them, but the normal way of preallocating them isn't working.

Does that make sense?  15-Moonstone
(To:ptc-3031221)

Something like this? Alan  19-Tanzanite
(To:ptc-3031221)
 Normally you do this by specifying a value of zero to the last value of the matrix (extreme right, bottom cell).

You can enter anything into the last matrix element, it doesn't have to be zero. In the rather trivial example I showed the last element is 2, and I allocated that first. If you delete the lines assigning functions to M0 and M1 you will see you have a three element vector, with the first two elements set to zero.

Preallocation actually makes much less difference in the latest version of Mathcad. It used to make a huge difference, but not any more. Announcements
Check out the latest