Programming Question

Well that's not correct anyway, it only looks for 2 consecutive values being equal and doesn't terminate otherwise. Also, it indexes an array with -1 = bad mojo.

EDIT: But in VB it would be something like (with bug fixed)

array(0) = 0 'Initial value of x
i = 0
y = 2 'value of y, you want to iterate over several values of y


Do
i = i + 1
array(i) = y*array(i-1)*(1-array(i-1))
While array(i) <> array(i-1)

EDIT: 2 bugs in code fixed ;)
 
^^ Of course, that's not right either.

1) You need to have 2 loops, one to fill in the current value with the calculated from the last value, the other to check the current value against all previous calculated values
2) You need to check for equality using a tolerance value (epsilon)
 
1) You need to have 2 loops, one to fill in the current value with the calculated from the last value, the other to check the current value against all previous calculated values

I would use a construct such as a list or an array instead of building one from scratch and using a loop, here.

Not sure what VB would have available for that, but there's likely exist something he could use.
 
Yeah that is correct warpus but you only need to return the array from the first occurrence of the equal value up the second occurrence, that is the stable orbit of the attractor. It may take some time to settle down into a stable orbit.

And again, don't test for equality, use a tolerance value ABS(val1-val2)<smallvalue, and you need a fail safe bail-out because the period of the orbits gets very large for certain values.

EDIT: I'm not familiar with VB (much) either but could knock up a C++ version pretty quick, I'd use a vector (resizeable array) then.
 
Back
Top Bottom