Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline themzlab  
#1 Posted : 15 February 2017 17:52:49(UTC)
themzlab

Rank: Newbie

Groups: Registered
Joined: 15/02/2017(UTC)
Posts: 2
United States
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 Good


mark

Edited by user 15 February 2017 23:48:47(UTC)  | Reason: Question totally answered!

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Davide Carpi  
#2 Posted : 15 February 2017 18:57:39(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,639
Man
Italy
Location: Italy

Was thanked: 1323 time(s) in 873 post(s)
Hello themzlab Offline ,

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
thanks 2 users thanked Davide Carpi for this useful post.
on 15/02/2017(UTC),  on 16/02/2017(UTC)
Offline themzlab  
#3 Posted : 15 February 2017 21:33:12(UTC)
themzlab

Rank: Newbie

Groups: Registered
Joined: 15/02/2017(UTC)
Posts: 2
United States
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?).

Offline Jean Giraud  
#4 Posted : 15 February 2017 22:52:05(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

Was thanked: 980 time(s) in 808 post(s)
Originally Posted by: themzlab Go to Quoted Post
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).



thanks 1 user thanked Jean Giraud for this useful post.
on 16/02/2017(UTC)
Offline Davide Carpi  
#5 Posted : 15 February 2017 23:41:17(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,639
Man
Italy
Location: Italy

Was thanked: 1323 time(s) in 873 post(s)
You are welcome Good

Originally Posted by: themzlab Go to Quoted Post
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
Offline Jean Giraud  
#6 Posted : 16 February 2017 19:27:53(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,868
Canada

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).
Users browsing this topic
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.