Skip to main content
1-Visitor
October 6, 2010
Solved

How to Optimize worksheet

  • October 6, 2010
  • 25 replies
  • 8983 views

My mathcad worksheet is crazy slow. I have highlighted the problem code in yellow box.

I have named it ProblemDate(d). Once you rename it Date(d) it's gonna slow down a lot.

scroll down slowly and you will see that the equations are now taking more time to compute. Once you hit the first graph it will just go to sleep.

Can anyone tell me how to optimize it. i'm attaching my code. Mathcad 14 only. it contains scripts that mathcad 11 doesn't like.

Best answer by AlvaroDíaz

Richard Jackson wrote:

You can't.

That is not quite correct

Well, with mathcad it's true that almost always one can. In the attached optimization done; also only one script for enabling and not a "vectorization" but a "discretization" for dates failing in the year of the date given by "Num". As bonus, now works in mc11.

Regards. Alvaro.

25 replies

12-Amethyst
October 6, 2010

You can't. Script functions are only for do some few calculations, you can't call vbscript code a lot of times. If you want accelerete the code must to write a dll in c++ or the mathcad functions without scripting.

Without calling the script (ie, without renaming the date function) seems to be now enough quickly. Optimized via "not double eval the same", but just inside each function. It can be optimize more doing the same, but not calling some intermediate functions, and evaluating it inside some "important" functions.

Regards. Alvaro.

1-Visitor
October 6, 2010

But why is it calling the script so many times anyway.

Here is a simple example

F(x):= CallScript(x)

G(x,y):=F(x)+y

Now i plot G(1,y) versus y

I have already fixed the x value. the script should be run once and the result saved. why is it running for every value of y when it doesn't even depend on y.

If i was doing G(x,1) then i can understand why the script will have to run for every value of x.

1-Visitor
October 6, 2010

Ziyad Saeed wrote:

But why is it calling the script so many times anyway.

Here is a simple example

F(x):= CallScript(x)

G(x,y):=F(x)+y

Now i plot G(1,y) versus y

I have already fixed the x value. the script should be run once and the result saved. why is it running for every value of y when it doesn't even depend on y.

If i was doing G(x,1) then i can understand why the script will have to run for every value of x.

I'm afraid you're confused; you're calling F(x) for each value of y. If you know that F(x) is constant, then you should modify G(x,y) to reflect that. Even if you have G(1,y), that's still a call to F(x), by your own function definition.

TTFN

19-Tanzanite
October 6, 2010

Mathcad 14 only. it contains scripts that mathcad 11 doesn't like.

It's not the scripts, it's just the DMS function. If you define a DMS function it works fine. In fact, it doesn't have the speed problems that it has in version 14!

1-Visitor
October 6, 2010

the FillVec to create the hrs variable instead of a range variable should be part of the optimizing tips section somewhere.

19-Tanzanite
October 6, 2010

There are many versions of that function kickng around, both with that name and with different names. In my opinion it should be a built in Mathcad function.