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 - Сообщения

#1 Опубликовано: 15.02.2017 11:52:49
Mark

Mark

0 сообщений из 3 понравились пользователям.

Группа: User

calculation time problem-2.sm (14 КиБ) скачан 136 раз(а).

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 Опубликовано: 15.02.2017 12:57:39
Davide Carpi

Davide Carpi

1417 сообщений из 2873 понравились пользователям.

Группа: 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 КиБ) скачан 216 раз(а).

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 пользователям понравился этот пост
Mark 15.02.2017 15:26:00, sergio 16.02.2017 05:28:00
#3 Опубликовано: 15.02.2017 15:33:12
Mark

Mark

0 сообщений из 3 понравились пользователям.

Группа: 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 Опубликовано: 15.02.2017 16:52:05
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 КиБ) скачан 89 раз(а).

Inst_PID [MCD Model].sm (176 КиБ) скачан 88 раз(а).



1 пользователям понравился этот пост
Mark 15.02.2017 18:25:00
#5 Опубликовано: 15.02.2017 17:41:17
Davide Carpi

Davide Carpi

1417 сообщений из 2873 понравились пользователям.

Группа: 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 Опубликовано: 16.02.2017 13:27:53
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 КиБ) скачан 82 раз(а).
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений