Sometimes VERY slow calculation time in program loops

Sometimes VERY slow calculation time in program loops - 10 loops may be ok, but geometric/exponential slowness from larger N - Messages

#1 Posted: 2/15/2017 11:52:49 AM
Mark

Mark

0 likes in 3 posts.

Group: User

calculation time problem-2.sm (14 KiB) downloaded 115 time(s).

hi all,

I am new to SMath but have 20 years experience with similar software.

I've struggled to find some problems when doing loops in a program. The math is very simple but
I am seeing calculating times in the seconds to minutes for things that should be far under 1 second.

Am I doing something wrong or is there some kind of issue. I first saw this problem in Linux
but this recent example is on Windows 7, SMath Studio Desktop 64-bit 0.98 build 6179

The attached file will calculate quickly as it stands, but there are disabled math regions highlighted
in RED that if enabled will dramatically slow down the calculation.

I have tried some optimizations such as setting the calculation to Numeric (not Symbolic) and
though I don't understand it, I wrapped my loop functions inside eval().

any ideas are greatly appreciated


mark
#2 Posted: 2/15/2017 12:57:39 PM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Hello [userlink]themzlab[/userlink],

attached a faster version, <0.4s on my machine; in light blue modifications and suggestions

calculation time problem-2.sm (15 KiB) downloaded 198 time(s).

Reason is that you are using procedures (list of commands behind a line() function immediatly on the RHS of an assignment); these aren't evaluated until you use them (hover the mouse over the definition to see what is stored in the engine). Since they doesn't depends from variables defined after them, you can evaluate each one at once assigning to a new variable (with the same name in the example above, but this doesn't matter, you can choose the name you want and then use this new variable in calculations to not evaluate the whole procedure again and again).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
2 users liked this post
Mark 2/15/2017 3:26:00 PM, sergio 2/16/2017 5:28:00 AM
#3 Posted: 2/15/2017 3:33:12 PM
Mark

Mark

0 likes in 3 posts.

Group: User

Thanks so much Davide for the quick reply. That correction does work!

I have a follow up question, does using the function eval() on the expressions in the loop do anything in this context (inside that loop inside the program?).

#4 Posted: 2/15/2017 4:52:05 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

I am new to SMath but have 20 years experience with similar software.



Which similar software ? Never mind.
The attached PID Model may contain some useful informations.

calculation time problem-2.sm (17 KiB) downloaded 70 time(s).

Inst_PID [MCD Model].sm (176 KiB) downloaded 70 time(s).



1 users liked this post
Mark 2/15/2017 6:25:00 PM
#5 Posted: 2/15/2017 5:41:17 PM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

You are welcome

Wrote

I have a follow up question, does using the function eval() on the expressions in the loop do anything in this context (inside that loop inside the program?).



it depends.

eval() triggers a numerical evaluation of his content; in other words, it returns a number with a 15 digits precision. In a heavy loop might be useful to make it faster, if his content contains a stack of operations from previous loops or functions that behaves differently in numerical or symbolical mode. If eval() is applied on a function that is pure numerical, it changes nothing.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#6 Posted: 2/16/2017 1:27:53 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

The rule about eval(,) is that there is no fixed rule,
whereas it associates with the suite of the project.
Reach the bottom of the attached work sheet, read at
the big turquoise arrow.

Jean

Image RGBYCM.sm (292 KiB) downloaded 61 time(s).
  • New Posts New Posts
  • No New Posts No New Posts