Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline Tim Gowing  
#1 Posted : 11 October 2017 20:17:44(UTC)
Tim Gowing


Rank: Member

Groups: Registered
Joined: 16/05/2017(UTC)
Posts: 14
United Kingdom

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.
graph.JPG
Regards, Tim
Offline Jean Giraud  
#2 Posted : 11 October 2017 21:25:59(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 2,030
Canada

Was thanked: 497 time(s) in 384 post(s)
Just define your 'x' vector of values, include in small loop.

AtWill.sm (7kb) downloaded 9 time(s).
Offline Tim Gowing  
#3 Posted : 11 October 2017 21:49:55(UTC)
Tim Gowing


Rank: Member

Groups: Registered
Joined: 16/05/2017(UTC)
Posts: 14
United Kingdom

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
Offline CBG  
#4 Posted : 11 October 2017 23:42:16(UTC)
CBG


Rank: Advanced Member

Groups: Registered
Joined: 14/10/2015(UTC)
Posts: 73

Was thanked: 14 time(s) in 11 post(s)
I do not see any problem.

hc_full.png
Offline Jean Giraud  
#5 Posted : 12 October 2017 04:22:09(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 2,030
Canada

Was thanked: 497 time(s) in 384 post(s)
Originally Posted by: Tim Gowing Go to Quoted Post
I 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 (14kb) downloaded 7 time(s).
Offline Jean Giraud  
#6 Posted : 12 October 2017 04:28:28(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 2,030
Canada

Was thanked: 497 time(s) in 384 post(s)
... 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.
Offline Tim Gowing  
#7 Posted : 12 October 2017 11:28:21(UTC)
Tim Gowing


Rank: Member

Groups: Registered
Joined: 16/05/2017(UTC)
Posts: 14
United Kingdom

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.
Capture1a.JPG

The 1.589 value is absent from the z range.
Capture1.JPG

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.
Capture2.JPG

Have I contravened a working principle in some way?

Tim
Offline Tim Gowing  
#8 Posted : 12 October 2017 11:38:09(UTC)
Tim Gowing


Rank: Member

Groups: Registered
Joined: 16/05/2017(UTC)
Posts: 14
United Kingdom

Redefining hc_full using hc_full:=hc_full also fixes the z range array.
Tim
Offline Jean Giraud  
#9 Posted : 12 October 2017 19:05:33(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 2,030
Canada

Was thanked: 497 time(s) in 384 post(s)
Originally Posted by: Tim Gowing Go to Quoted Post
Have 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 (188kb) downloaded 7 time(s).
Offline mkraska  
#10 Posted : 12 October 2017 23:45:07(UTC)
mkraska


Rank: Advanced Member

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

Was thanked: 631 time(s) in 419 post(s)
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
loop.sm (5kb) downloaded 9 time(s).

Edited by user 12 October 2017 23:47:12(UTC)  | Reason: Not specified

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://en.smath.info/wi...th%20with%20Plugins.ashx
Offline Jean Giraud  
#11 Posted : 13 October 2017 04:12:01(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 2,030
Canada

Was thanked: 497 time(s) in 384 post(s)
True Martin: that damned floating point often creates a very small imaginary.
Offline Jean Giraud  
#12 Posted : 13 October 2017 05:22:25(UTC)
Jean Giraud


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 2,030
Canada

Was thanked: 497 time(s) in 384 post(s)
In the context of this topic, there was an example in Mathcad 8.
About solving an RK DE relative to "Orbit" by Steven Finch.
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.