newb needs help with logistic equation
binky
Posts: 3
Hello!
Just starting with the Propellor. Got most things down but I'm having a hard time with the logistic equation. i"m sure it's something very simple that I'm over looking. It's kind of bloat code but that's not a concern at this point, I'm just trying to get the logistic equation to print out to the terminal. I'm only having problems with the algorithm, not with the terminal. Thanks!
Just starting with the Propellor. Got most things down but I'm having a hard time with the logistic equation. i"m sure it's something very simple that I'm over looking. It's kind of bloat code but that's not a concern at this point, I'm just trying to get the logistic equation to print out to the terminal. I'm only having problems with the algorithm, not with the terminal. Thanks!
{logistic equation printed to terminal} CON _clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz _xinfreq = 5_000_000 VAR long stack[100] long k long x[2] long temp[2] OBJ BS2 : "BS2_Functions" ' Create BS2 Object f : "float32full" pst : "Parallax Serial Terminal" fString : "FloatString" PUB main cognew(start, @stack[0] ) 'init start cog BS2.start (31,30) 'Initialize BS2 Object timing, Rx and Tx pins for DEBUG pst.Start(115_200) 'init pst f.start 'init float PUB start 'logistic equation ' x(i+1)=k*x(i)*(1-x(i)); k:=3.8 'constant x[0]:= 2.0 'start variable x[1] := 2.0 temp[0] := 1.0 temp[1] := 1.0 repeat x[1] := x[0] temp[0] := f.fMul(k, x[0]) ' r*x(i) temp[1] := f.fsub (1.0 , x[0]) ' (1-x(i)) x[1] := f.fmul(temp[0], temp[1]) pst.str(fstring.FloatToString(x[1])) 'print to terminal bs2.pause(200) 'wait 200 msec pst.clear 'clear terminal 'go back to top of loop
Comments
First of all you should take care of the order of starting stuff. In your code you started your calculation before you started float and pst, but these are used by your calculations. Here the result is unpredictable. I did not analyse whether it caused a problem in your code - propably not because I got the same result after 'fixing' it.
Additionally I added a waiting loop because switching to PST takes a while. This way the interesting thing waits for you to be started with a keypress in PST.
And finally the BUG:
x[0]:=x[1]
Is the thing you want to do at the beginning of the loop. Guess you can figure out yourself why?!
Unfortunately, the outputs should always be between 0-4 and chaotic at k=3.57 and there's still an error in the algorithm that I'm not figuring out. I'm an analog guy and usually build chaotic oscillators in analog. There is just one piece of the puzzle that I can't figure out to get the logistic equation to work in SPIN. This just quickly goes out of bounds.
http://www.stsci.edu/~lbradley/seminar/logdiffeqn.html
I would say it diverges for any starting value greater than 1.
Massimo
I really appreciate the help offered by forum members here!
edit: yup, period 4 at k=3.52, chaotic at k=3.82 and solid long term period 3 at k=3.828427. Period 3 is always what I look for in a (analog) chaotic oscillator and is a small "island of stability" in a chaotic system. Period 6 at k=3.84 showing period doubling and back to chaos at k=3.85.
BTW, the Propellor is going to be tied into some sine wave oscillators for robotic locomotion. A vid I made for a 555 timer competition (took grand prize, I won a Fluke 287 and 2 mini oscilloscopes) that gives some detail on the analog side. Forrest Mims and Hans Camenzind (creator of the 555 timer and 40 other chips) were the final judges.
http://www.youtube.com/watch?v=uXeSsevsNNE
Also, if one wants learn to make a quick and dirty balancing robot, it can be done with either a 555 timer chip or a 2 transistor multivibrator. It'll help one understand PID systems.
http://www.youtube.com/watch?v=Y-afnY32RrY&list=UUpfn9vk8fDuEx5ZtcNLXLCQ&index=2&feature=plcp
Wow, these are keepers, binky!
Excellent.