1 Pages (12 items)
for loop counter - Messages
#1 Posted: 10/11/2017 2:17:44 PM
Hi,
I wish to loop through the YR formula, in pic below, for values of z being 0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.589.
My progress so far is to produce an array evenly spaced z values and if the 1.0001 factor is not applied to hc_full then the last element of the z array is 1.362, rather than 1.589.
It is obvious to me that I have some missing skill here, please throw me some hints.

Regards, Tim
I wish to loop through the YR formula, in pic below, for values of z being 0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.589.
My progress so far is to produce an array evenly spaced z values and if the 1.0001 factor is not applied to hc_full then the last element of the z array is 1.362, rather than 1.589.
It is obvious to me that I have some missing skill here, please throw me some hints.
Regards, Tim
#2 Posted: 10/11/2017 3:25:59 PM
Just define your 'x' vector of values, include in small loop.
AtWill.sm (6 KiB) downloaded 60 time(s).
AtWill.sm (6 KiB) downloaded 60 time(s).
#3 Posted: 10/11/2017 3:49:55 PM
Hi Jean,
Thank you for the example file, I will study this for better understanding.
I have longer arrays to create also so wish to automate; if I make z as in the pic or with equal spacing, is there a means of appending the final (1.589) value to the end of the array?
Tim
Thank you for the example file, I will study this for better understanding.
I have longer arrays to create also so wish to automate; if I make z as in the pic or with equal spacing, is there a means of appending the final (1.589) value to the end of the array?
Tim
#5 Posted: 10/11/2017 10:22:09 PM
WroteI have longer arrays to create also so wish to automate;
If you have longer array, equally spaced => as easy.
Naturally, if not equally spaced, must be manual.
AtWill.sm (13 KiB) downloaded 39 time(s).
#6 Posted: 10/11/2017 10:28:28 PM
... if they are not equally spaced, but if there is a bit
of logic in the spacing, we can select from a list that
can be made/refactored as you wish at will from a little
counter loop.
of logic in the spacing, we can select from a list that
can be made/refactored as you wish at will from a little
counter loop.
#7 Posted: 10/12/2017 5:28:21 AM
Jean,
Thank you for the counter loop example, this will stretch my programming comprehension.
CBG,
Thank you for typing the work from scratch, and showing no issue with the 1.589 value.
I redefined hc_full immediately above the z range call and then the output changed to match your results.
The hc_full is defined with an if statement.

The 1.589 value is absent from the z range.

The hc_full is redefined directly above the z range call (to override the value produced by the if statement) and the 1.589 value is now present in the z range.

Have I contravened a working principle in some way?
Tim
Thank you for the counter loop example, this will stretch my programming comprehension.
CBG,
Thank you for typing the work from scratch, and showing no issue with the 1.589 value.
I redefined hc_full immediately above the z range call and then the output changed to match your results.
The hc_full is defined with an if statement.
The 1.589 value is absent from the z range.
The hc_full is redefined directly above the z range call (to override the value produced by the if statement) and the 1.589 value is now present in the z range.
Have I contravened a working principle in some way?
Tim
#8 Posted: 10/12/2017 5:38:09 AM
Redefining hc_full using hc_full:=hc_full also fixes the z range array.
Tim
Tim
#9 Posted: 10/12/2017 1:05:33 PM
WroteHave I contravened a working principle in some way?
Maybe not ? work sheet would help and no help.
Smath 6179 does not take index on the RHS.
hopper.sm (187 KiB) downloaded 34 time(s).
#10 Posted: 10/12/2017 5:45:07 PM
for(3)-loops with initial, second and maximum value aren't robust if floating point values are specified. The internal representation of such numbers may differ from what is displayed due to round-off.
Due to this it is not good programming style to test the equality of two floating point numbers without specifying a tolerance. If you want to be safe, you either introduce such a tolerance or you generate the list of values based on a list of integers.
It should be possible to modify for(3) such that the tolerance is generated as a fraction of the difference between first and second value.
![2017-10-12 22_36_42-SMath Studio - [Blatt4_].png](/en-US/file/PacnKP/2017-10-12-22_36_42-SMath-Studio---_Blatt4___png)
loop.sm (4 KiB) downloaded 36 time(s).
Due to this it is not good programming style to test the equality of two floating point numbers without specifying a tolerance. If you want to be safe, you either introduce such a tolerance or you generate the list of values based on a list of integers.
It should be possible to modify for(3) such that the tolerance is generated as a fraction of the difference between first and second value.
loop.sm (4 KiB) downloaded 36 time(s).
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#11 Posted: 10/12/2017 10:12:01 PM
True Martin: that damned floating point often creates a very small imaginary.
#12 Posted: 10/12/2017 11:22:25 PM
In the context of this topic, there was an example in Mathcad 8.
About solving an RK DE relative to "Orbit" by Steven Finch.
About solving an RK DE relative to "Orbit" by Steven Finch.
1 Pages (12 items)
-
New Posts
-
No New Posts