1 страниц (8 вхождений)
While loops - How to recover multiple parameter values from within a while loop - Сообщения
#1 Опубликовано: 21.07.2014 08:46:50
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 ?
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 ?
#2 Опубликовано: 21.07.2014 09:47:04
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
![2014-07-21 15_56_27-SMath Studio Desktop - [while.sm_].png](/ru-RU/file/6y8zmX/2014-07-21-15_56_27-SMath-Studio-Desktop---_while_sm___png)
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

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#3 Опубликовано: 21.07.2014 10:27:52
Wrote
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
loop.sm (7 КиБ) скачан 70 раз(а).
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#4 Опубликовано: 21.07.2014 11:19:02
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
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
#5 Опубликовано: 21.07.2014 13:21:20
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://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#6 Опубликовано: 23.07.2014 05:53:32
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
testcase.sm (13 КиБ) скачан 75 раз(а).
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
testcase.sm (13 КиБ) скачан 75 раз(а).
#7 Опубликовано: 23.07.2014 06:19:27
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
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
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#8 Опубликовано: 23.07.2014 08:55:17
Davide, Martin and Radovan - all is now solved and numbers emerge efficiently from the while loop !!
Many thanks for all of your help.
Michael
1 страниц (8 вхождений)
-
Новые сообщения
-
Нет новых сообщений