FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Simulation, Artificial Life
(Moderator: REAS)
   logistic equation
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: logistic equation  (Read 536 times)
Jean-Jacques

WWW
logistic equation
« on: Jan 15th, 2004, 1:12am »

Hello,
I would like to implement a logistic equation, after several attempts I still can't do it even if it appears simple.
 
This is the logistic equation that i try to implement:
 
Xn+1=RXn(1-Xn)
 
where X = original account
where R = growth rate
 Xn = where n is 1 after the first iteration, 2 after the second etc....
 
Your help is welcome !
 
Jean-Jacques

WWW
Re: logistic equation
« Reply #1 on: Jan 15th, 2004, 1:36am »

this is the most ugly code you've ever seen about logistic equation.
I'm sure that i must use loops for this but i don't know how !
 
Very ugly logistic equation:
 
float x = 0.1;  
float rate = 2;
float X0 = 0;
float X1 = 0;
float X2 = 0;
float X3 = 0;
 
X0=(rate*x)*(1-x);  
println(X0);
X1=(rate*X0)*(1-X0);
println(X1);
X2=(rate*X1)*(1-X1);
println(X2);
X3=(rate*X2)*(1-X2);
println(X3);
 
If someone could help me to give a structure to this code  ?
 
If someone could help me to avoid the repetitions into this code ?
: )
 
Bijeoma

myloveiloved
Re: logistic equation
« Reply #2 on: Jan 15th, 2004, 3:20am »

//n = number of iterations
int n = 4;
 
//x0, x1, x2, xn...
float[] values = new float[n];
 
float rate = 2;  
 
//x
float init_val = 0.1  
 
values[0] = (rate * init_val) * ( 1 - init_val);
 
for( int i = 1; i < n + 1; i++ ) {
  values[i] = (rate * values[i-1]) * (1 - values[i-1]);  
  println(values[i];  
}
 
i just woke up i and im brain dead on how to insert code... i also didnt bother testing the code. but i think it should work.
 
bryan
« Last Edit: Jan 15th, 2004, 3:25am by Bijeoma »  
Jean-Jacques

WWW
Re: logistic equation
« Reply #3 on: Jan 15th, 2004, 11:20am »

thank you for your help.
In order to post some code "it works like an html tag - you have to put a [ code ] at the begining, and a [/ code ] at the end (without the spaces before and after the word "code")."
 
I tried your code,i've added a ";" and a ")" but it stills doesn't work.
I'm trying to debug it but i'm not sure to succeed.
This is the new code version:
 
Code:

 //n = number of iterations
int n = 4;
 
//x0, x1, x2, xn...
float[] values = new float[n];
 
float rate = 2;  
 
//x
float init_val = 0.1  ;
 
values[0] = (rate * init_val) * ( 1 - init_val);
 
for( int i = 1; i < n + 1; i++ ) {
  values[i] = (rate * values[i-1]) * (1 - values[i-1]);  
  println(values[i]);  
}  

I obtain this error message:
java.lang.ArrayIndexOutOfBoundsException: 4
 
 at Temporary_6985_838.draw(Temporary_6985_838.java:15)
 
 at BApplet.nextFrame(BApplet.java:407)
 
 at BApplet.run(BApplet.java:369)
 
 at java.lang.Thread.run(Thread.java:536)
 
« Last Edit: Jan 15th, 2004, 11:58am by Jean-Jacques »  
toxi

WWW
Re: logistic equation
« Reply #4 on: Jan 15th, 2004, 12:04pm »

if you only have "n" elements in your array and knowing array indexes start at 0, the "for" loop should terminate at "n" not at "n+1"... so write the line like that and it should work:
 
Code:
for( int i = 1; i < n; i++ ) {
 

http://toxi.co.uk/
Jean-Jacques

WWW
Re: logistic equation
« Reply #5 on: Jan 15th, 2004, 12:21pm »

You're right Toxi now it works, this is the working code:
Code:

//This code is an attempt to implement a simple logistic equation
//based upon http://sprott.physics.wisc.edu/sa.htm
//As a newbie i did not succed to write this code on my own,
//Bijeoma and Toxi helped me a lot thank you guys !
//january,15,2004 Duclaux Jean Jacques
 
 
 
//n = number of iterations
int n = 4;
 
//x0, x1, x2, xn...
float[] values = new float[n];
 
//Here you define the rate  
float rate = 2;  
 
//x this is the initial value
float init_val = 0.1  ;
 
//calculate for X0  
values[0] = (rate * init_val) * ( 1 - init_val);
 
//print X0 value
println(values[0]);
 
//start the loop and calculate for i= 1 to n  
for( int i = 1; i < n; i++ ) {
//print i
println(i);
 
//this is the logistic equation
 values[i] = (rate * values[i-1]) * (1 - values[i-1]);  
 
//print values for i= 1 to 4  
println(values[i]);  
}  
 
 
Pages: 1 

« Previous topic | Next topic »