SMath Studio Forum
»
SMath Studio
»
Questions
»
Sometimes VERY slow calculation time in program loops
Rank: Newbie
Groups: Registered
Joined: 15/02/2017(UTC) Posts: 2 Location: usa
|
calculation time problem-2.sm (15kb) downloaded 88 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 Edited by user 15 February 2017 23:48:47(UTC)
| Reason: Question totally answered!
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,639 Location: Italy Was thanked: 1323 time(s) in 873 post(s)
|
Hello
themzlab
, attached a faster version, <0.4s on my machine; in light blue modifications and suggestions calculation time problem-2.sm (16kb) downloaded 165 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). Edited by user 15 February 2017 19:04:07(UTC)
| Reason: Not specified |
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
2 users thanked Davide Carpi for this useful post.
|
on 15/02/2017(UTC), on 16/02/2017(UTC)
|
|
Rank: Newbie
Groups: Registered
Joined: 15/02/2017(UTC) Posts: 2 Location: usa
|
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?).
|
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,868 Was thanked: 980 time(s) in 808 post(s)
|
Originally Posted by: themzlab 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 (18kb) downloaded 43 time(s). Inst_PID [MCD Model].sm (177kb) downloaded 44 time(s).
|
1 user thanked Jean Giraud for this useful post.
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,639 Location: Italy Was thanked: 1323 time(s) in 873 post(s)
|
You are welcome Originally Posted by: themzlab 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 consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects |
|
|
|
Rank: Guest
Groups: Registered
Joined: 04/07/2015(UTC) Posts: 6,868 Was thanked: 980 time(s) in 808 post(s)
|
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 (293kb) downloaded 46 time(s).
|
|
|
|
SMath Studio Forum
»
SMath Studio
»
Questions
»
Sometimes VERY slow calculation time in program loops
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.