Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Calculation time

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

07-16-2013
03:00 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2013
03:00 PM

Calculation time

How can I improve the calculation time? Especially for the solve blocks.

Any files that I can read? Tips? The file * Improving Mathcad Calculation Speed *was recently removed from the site.

Thank you,

Mihai Moraru

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

07-18-2013
03:02 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-18-2013
03:02 PM

OK, the second solve block calls a parameterized solve block. It's loop within a loop, and if one pass of the inner loop takes 0.25 seconds then that's going to be slow! If the first solve block has 6 parameters and 11 equations then it is also a minimization problem (as opposed to Find). Can you reformulate the problem to put everything in one solve block? Failing that, the only solution is to speed up the first solve block. Can you say any more about the equations in that solve block?

12 REPLIES 12

07-16-2013
04:43 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-16-2013
04:43 PM

MihaiMoraru wrote:

How can I improve the calculation time? Especially for the solve blocks.

There is no general answer to this question - it depends on a lot of factors.

If you have a concrete problem you may post the sheet and see if someone comes up with a speed up.

Any files that I can read? Tips? The file

was recently removed from the site.Improving Mathcad Calculation Speed

Usually files ond postings are not removed from this forum.

You don't state which Mathcad version you are working with, so I assume Mathcad 15.

Maybe you are talking about the quicksheet: Click "Help"/"Quicksheets"/"Mathcad Techniques"/"Improving Calculation Speed"

You may also search this forum for "calculation speed" or similar.

What we found out here a sghort time ago was that programs using stack() and augment() are much slower than programs with selfwritten routines - incomprehensible, but true.

07-26-2013
06:24 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2013
06:24 PM

Werner Exinger wrote:

What we found out here a sghort time ago was that programs using stack() and augment() are much slower than programs with selfwritten routines - incomprehensible, but true.

Indeed, it is better to create your own routine instead of using stack(). The built-in routine was slower than my routine for arranging the solution of a SolveBlock.

Thank you Werner.

07-17-2013
01:28 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-17-2013
01:28 AM

MihaiMoraru wrote:

...The file

was recently removed from the site...Improving Mathcad Calculation Speed

"**Improving Mathcad Calculation Speed**" article from PTC Express:

http://www.imakenews.com/ptcexpress/e_article001093581.cfm?x=bcG4481,b3jsqcsB,w

http://www.imakenews.com/eletra/gow.cfm?z=ptcexpress%2C262285%2Cb3jsqcsB%2C2340181%2CbcG4481

The worksheet for MC13 can be found in attachment.

07-17-2013
09:10 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-17-2013
09:10 AM

As Werner says, there's no simple answer to that question. Posting a worksheet would help a lot.

Here is one thread that expands (a lot) on what the quicksheet says about vectorization:

07-17-2013
12:23 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-17-2013
12:23 PM

I would like to upload it... unfortunetly I cannot , and is not due to the 'advanced editor'.

But I can tell a bit more on the worksheet. Briefly:

- one parameterized (6 parameters) SolveBlock (11 equations)

- one objective function formed using the (partial) solution of the parameterized SolveBlock: an SSE = sum(exp(i)-calc(i))^2, i=1..7

- one SolveBlock for minimization of the SSE function (containing the 6 parameters)

So, how do I improve the calculation time when dealing particularly with SolveBlocks?

About two hours it takes to solve the optimization problem - MathcadPrime2.0.

I read the QuickSheets (Werner Exinger), the article (VladimirN.) and the thread (Richard Jackson) and is very helpful. Thank you all very much.

Mihai

07-17-2013
12:32 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-17-2013
12:32 PM

Really hard to say w/o the sheet (and probably hard with the sheet, too). Whats the problem with uploading? Technical problem (try later again; I sometimes have those probs with inserting pics in my posts) or because of proprietary confidential data in the sheet?

Don't be sure from your description if it could help (in fact I doubt it), but in Prime2 you can turn on multithreading which should speed up parallel calculations on multiprocessor machines.

07-18-2013
12:15 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-18-2013
12:15 PM

Werner Exinger wrote:

Whats the problem with uploading? Technical problem (try later again; I sometimes have those probs with inserting pics in my posts) or because of proprietary confidential data in the sheet?

Proprietary unfortunately.

Werner Exinger wrote:

Don't be sure from your description if it could help (in fact I doubt it), but in Prime2 you can turn on multithreading which should speed up parallel calculations on multiprocessor machines.

With and without multithreading the same number of CPUs are used and the same CPUs usage %. Interesting is that the later is about 20%... I was expecting to be 80 - 90% (independent of activated or not the multithreading option). I will give it a full try.

Thank you.

07-17-2013
12:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-17-2013
12:49 PM

I assume exp(i) means experimental. Calculate a vector of residuals rather than the SSE.

Resid(parameters):=exp(i)-calc(i)

Pass the vector of residuals to the solve block

Given

Resid(parameters)=0

Answer:=minerr(parameters)

That is faster in Mathcad 15. I've never tried it in Prime, but it may also be faster.

Having said that, with only 7 experimental values to fit it should usually converge in less than a second. Can you tell us more about the formula for calc(i)? Does it contain numeric integrals, derivatives? Does it take a long time to calculate one value? I suspect that's where the root of the problem lies.

07-18-2013
12:43 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-18-2013
12:43 PM

Richard Jackson wrote:

I assume exp(i) means experimental. Calculate a vector of residuals rather than the SSE.

Resid(parameters):=exp(i)-calc(i)

Pass the vector of residuals to the solve block

Given

Resid(parameters)=0

Answer:=minerr(parameters)

Yes, exp(i) means experimental. I calculated a vector of residuals (using only one parameter to solve for so I can have a quick insight) and used minerr instead of Minimize. And indeed, miner is faster but it saved only 1 min (from 20 to 19).

Using the residuals or SSE makes almost no difference (0.2 min - one parameter as before) - at least in my calculations.

Richard Jackson wrote:

Can you tell us more about the formula for calc(i)? Does it contain numeric integrals, derivatives?

The equations in the first SolveBlock contains nonlinear terms, but does not contains integrals or derivatives.

Richard Jackson wrote:

Does it take a long time to calculate one value? I suspect that's where the root of the problem lies.

The solution of the first SolveBlock takes about 0.25 sec, so at least we identified the (block) root of the problem.

I tried also different initial guesses, scaled the 6 parameters in the same order of magnitude... without any improvement. I will investigate more. Thank you very much for the help.

Mihai

07-18-2013
03:02 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-18-2013
03:02 PM

07-19-2013
12:14 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-19-2013
12:14 PM

Richard Jackson wrote:

Can you reformulate the problem to put everything in one solve block? Failing that, the only solution is to speed up the first solve block. Can you say any more about the equations in that solve block?

I could try to reformulate that in a single block, however I have some concerns that it will work. The solution calc(i) comes from the block in the form of calc(c1, c2... cN, p1,p1... p6), where c1... cN are vectors of 7 values each, since each experiment comes with a set of N constants. In the SolveBlock, I keep them as parameters - free - as shown... and after the block I insert the values. This leads me to the calc(p1, p2... p6) solution (of course, including any 6 values for the parameters, this solution is a 7 x 11 matrix). So, I do not think that inside the SolveBlock is allowed to write the equations in the form: x[i **=** z[i

However, I am not sure if I could use the vectorized form x **=** z (with the vectorization arrow above both, x and z).

And even if I succeed in doing everything in a SolveBlock and use minner, at a later stage I will have to include in the model the derivatives of the current equations. So, I would have to both integrate (most probably using Odesolve) and to make the optimization using minerr or minimize... and therefore, I would need again the two SolveBlocks.

So, what I can do is to reduce the calculation time for any individual operation/block that I have. Following this idea, I removed from the first SolveBlock the equations of the form f(unknown1, unknown2,...) and I included their actual axpressions (e.g. unknown1 + unknown2 * unknown3, etc). And this gave me an improvement.

But since I have to see if there are other minima (and there are) and see which is most satisfactory in terms of best fit (I always look at the SSE or reziduals), I have to start also from different guess values for the six parameters... and the calculation time is very sensitive to that.

I will keep looking for improvements. Thank you for your reply; they are very helpful.

07-26-2013
06:15 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-26-2013
06:15 PM

So, from what I learned, the calculation time can be reduced by:

- using a single SolveBlock instead of multiple, where possible

- writing the actual expressions in the SolveBlock, and not calling them (do not define them 'above' the SolveBlock and then use them in the block)

In calculation loops, reducing the limiting calculation sequence will reduce the overall calculation time.

Basically, it is about reducing the number of operations and function evaluations as much as possible.

At least, these gave some improvement in my calculations.