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

Calculation time

SOLVED
Highlighted
Newbie

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Calculation time

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?

View solution in original post

12 REPLIES 12

Re: Calculation time

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 Improving Mathcad Calculation Speed was recently removed from the site.

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.

Re: Calculation time

MihaiMoraru wrote:

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

"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.

Re: Calculation time

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:

http://communities.ptc.com/message/154931#154931

Re: Calculation time

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

Re: Calculation time

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.

Re: Calculation time

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.

Re: Calculation time

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.

Re: Calculation time

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

Re: Calculation time

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?

View solution in original post

Announcements