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 cartographer  
#1 Posted : 21 July 2014 15:46:50(UTC)
cartographer

Rank: Newbie

Groups: Registered
Joined: 21/07/2014(UTC)
Posts: 4
United Kingdom
Location: England

Hi ! I am in need of some help please from an Smath Studio expert.

I am fairly new to Smath and I am trying to port some maths (in fact two closely related programs that are largely spherical trig) to see if they will work in Smath. I have previously coded the software in Liberty Basic Pro, Python 3.4.1 and Mathcad (15 and Prime 3) and all give consistent, correct, results.

The code requires use of "while" loops within which to converge iterative elements of the math in each case. The problem is that it is necessary to get at the final values of several parameters that are used within the loops (6 in one case and 10 in the other) once convergence is complete. These values are then used for further, post convergence, calculations.

This is no problem in Liberty Basic and Python. However, it does not seem very easy (to me at least !)to produce "report quality" output via these options. Mathcad provides quality output, but the solution I found does not seem to work with Smath.

I have been exploring Smath for about a year and it now seems to have reached the stage (currently I am using RC 0.97.5301) where it can give good results. However, I cannot find any way of getting it to do what I need in respect of the recovery of multiple values from the while loops. I have been playing around with the use of column vectors to act as "containers" for returning the requisite values, but without success as yet. Am I on the right track ?

Can anybody help me please ?

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

Offline Davide Carpi  
#2 Posted : 21 July 2014 16:47:04(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 cartographer,

If you don't need to store intermediate results, you can use a standard while loop like the attached.
trace() function (wiki:trace) in this case helps a lot to debug.

In the other hand, if you need the collection of the values at any loop, you can use vectors/matrices to store the results.


Best regards,

Davide


P.S. Use numeric optimization to speed up calculations Wink

Edited by user 21 July 2014 18:26:03(UTC)  | Reason: Not specified

File Attachment(s):
while.sm (9kb) downloaded 90 time(s).
Davide Carpi attached the following image(s):
2014-07-21 15_51_18-SMath Studio Desktop - [while.sm].png
2014-07-21 15_56_27-SMath Studio Desktop - [while.sm_].png
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline mkraska  
#3 Posted : 21 July 2014 17:27:52(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,980
Germany

Was thanked: 1120 time(s) in 718 post(s)
Originally Posted by: cartographer Go to Quoted Post

The code requires use of "while" loops within which to converge iterative elements of the math in each case. The problem is that it is necessary to get at the final values of several parameters that are used within the loops (6 in one case and 10 in the other) once convergence is complete. These values are then used for further, post convergence, calculations.

If you just need a final set of values (and not the iteration history of the values) this is trivial for canvas-level loops, as the variables just have their last values and are visible outside the loop.

If the loop is part of a function body (right hand side of a function definition) then there are two ways to convey the result to the outer namespace:
- put the values in a vector or list and make that list the last instruction in the function body (return value).
- use assignments to function parameters
File Attachment(s):
loop.sm (8kb) downloaded 46 time(s).
mkraska attached the following image(s):
loop.PNG
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Offline cartographer  
#4 Posted : 21 July 2014 18:19:02(UTC)
cartographer

Rank: Newbie

Groups: Registered
Joined: 21/07/2014(UTC)
Posts: 4
United Kingdom
Location: England

w3b5urf3r, mkraska,

Many thanks to you both for your quick replies.

With regards to the info from mkraska, I can confirm that just the final values are sufficient. However, when I tried a simple while loop, any attempt to reads the final values resulted in empty placeholders with red boxes and "undefined" messages. I think I must be close and I am doing something silly. I will try again and see what I can do.

With regards to Davide's info, I see strong similarities with the advice from Martin. I will have a go at adapting his first sample of code and see what transpires.

Regards,

Michael
Offline mkraska  
#5 Posted : 21 July 2014 20:21:20(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,980
Germany

Was thanked: 1120 time(s) in 718 post(s)
You might consider showing us your .sm file with some indication of what you tried and what you actually expect.
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Offline cartographer  
#6 Posted : 23 July 2014 12:53:32(UTC)
cartographer

Rank: Newbie

Groups: Registered
Joined: 21/07/2014(UTC)
Posts: 4
United Kingdom
Location: England

Martin,

Re your suggestion to send my problem code, I originally resisted this as I did not want to trouble folk unduly. However, I have now extracted the problem while loop from what is a growing worksheet, and this is attached. I hope it is understandable !

Having looked the the earlier replies I received from you I cannot see why this does not work.

Thanks again for the help.


Michael
File Attachment(s):
testcase.sm (14kb) downloaded 57 time(s).
Offline omorr  
#7 Posted : 23 July 2014 13:19:27(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello Michael,

It seems here is a "standard" problem we bumped into (again).

Just right click on the while loop and choose Optimization->Numeric. Then you will get the results. This is advisable when you have only numerical calculations.

Regards,
Radovan

Edited by user 23 July 2014 13:21:18(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline cartographer  
#8 Posted : 23 July 2014 15:55:17(UTC)
cartographer

Rank: Newbie

Groups: Registered
Joined: 21/07/2014(UTC)
Posts: 4
United Kingdom
Location: England


Davide, Martin and Radovan - all is now solved and numbers emerge efficiently from the while loop !!

I have checked that numeric optimisation is on.
I have now added a vector within the loop in which to capture all of the required parameters.
Progress on my project will hopefully now be in a forwards direction once again !


Many thanks for all of your help.

Michael
Users browsing this topic
Similar Topics
Break for/while loops across pages (Questions)
by jaivishnu 20/04/2020 05:39:31(UTC)
evaluation inside for and while loops (Bugs & Problems)
by Davide Carpi 03/07/2012 14:11:47(UTC)
eval() and for/while loops (Bugs & Problems)
by Davide Carpi 28/05/2012 19:32:39(UTC)
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.