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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Slow matrix operation

DJF
16-Pearl
16-Pearl

Slow matrix operation

Attached is a little example of a problem I'm seeing - in simplified format only to demonstrate the issue.  Background - I'm doing a 2D finite difference problem and during setup mathcad slows down an unacceptable amount and I can't see why it should.  

 I tried it in 5.0 with no change.  On my machine the 'slow' program here takes about 5 seconds, while the 'fast' examples are instantaneous - as expected since there's no real calculation ongoing.

I don't see why it should slow down like this.  I suspect it's recalculating the 'node' matrix over and over. Or possibly a bug. Anything I'm doing wrong?  

 

4.0 and pdf attached. 

Thanks,

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby V
(To:DJF)

Your three routines create differently sized matrices ans so the time difference is understandable.

I renamed them and turned them into functions of a dummy argument for timing purposes:

B1.png

Its always a good idea to let Mathcad preallocate the memory for the full matrix first and dont't let the matrix "grow slowly". A simple modification to your slow routine makes it as fast as the others:

B2.png

View solution in original post

3 REPLIES 3
LucMeekes
23-Emerald III
(To:DJF)

Why would you index A with a column number from the node matrix?

Have you seen what the values in the node matrix are.

They run up to (Mdiv-1)*Ndiv+Ndiv, that is, the mximum number is 39*70+70=40*70=2800.

So all of a sudden you could be creating an element for A in its 2800th column.

Mathcad slows down when you change size of a matrix, I guess Prime is no exception.

 

I'm not surprised that Prime 5 shows the same behaviour. There's NO difference between Prime4 and Prime5, other than that Prime5 includes a 3rd party plotting tool.

 

Success!
Luc

 

Werner_E
24-Ruby V
(To:DJF)

Your three routines create differently sized matrices ans so the time difference is understandable.

I renamed them and turned them into functions of a dummy argument for timing purposes:

B1.png

Its always a good idea to let Mathcad preallocate the memory for the full matrix first and dont't let the matrix "grow slowly". A simple modification to your slow routine makes it as fast as the others:

B2.png

DJF
16-Pearl
16-Pearl
(To:Werner_E)

Thanks Werner, the preallocation does the trick.  I realize there are size differences between the examples, but a 2800x2800 matrix should be (and is) lightning fast, as I've played with much bigger ones without issue many times.  Lesson learned - although i actually always kinda liked how Mathcad doesn't require matrix definition.  First time it's ever gotten me in trouble, to my knowledge.

Top Tags