| | |
Malthusian Equation Help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
•
•
P = R*P*(1-P)
Input: R (growth rate parameter) Double values between 0 and 10.
Input: P (population) Double values between 0 and 1.
Output: P (New population) on the console in rows of five numbers
the exit conditions are the population becomes extinct or stable.
Extinction occurs when the new value of P is zero.
Stability occurs when the new value of P is the same as the previous value of P.
It is.
But you didn't even tell what the problem is.
Do you want to determine values of R for which a given P will yield a stable population?
Or maybe values of P for which a given R will yield a stable population?
Or what exactly do you want?
Once you know that you can start designing your code around that knowledge.
But you didn't even tell what the problem is.
Do you want to determine values of R for which a given P will yield a stable population?
Or maybe values of P for which a given R will yield a stable population?
Or what exactly do you want?
Once you know that you can start designing your code around that knowledge.
Java Syntax (Toggle Plain Text)
Method( double R, double P){ P = R*P*(1-P); return P; }
•
•
Join Date: Sep 2004
Posts: 84
Reputation:
Solved Threads: 1
You want to set up a loop. Save your initial 'P' value, then feed it back into the equation. Then check the result and determine if it is stable or Extinct.
You can put the below in it's own method called 'Malthusian':
Granted this is quick and dirty. I am assuming that one or the other value will be reached, but this could also cause an infinate loop.
You can put the below in it's own method called 'Malthusian':
Java Syntax (Toggle Plain Text)
public int Malthusian { double saveP; double newP; boolean bflag = true; int returnVal = 0; // Initial value // Assuming nano's method above returns a double: saveP = Method(5,1); while(bflag) { newP = Method(5,saveP); if (newP == saveP) { // Stable (do what you need to return this.) returnVal = 1; // Arbitrary value to denote Stable bflag = false; } if (P == 0) { // Extinct (do what you need to return this.) returnVal = 2; // Arbitrary value to denote Extinct bflag = false; } return returnVal; // Return the value } }
Granted this is quick and dirty. I am assuming that one or the other value will be reached, but this could also cause an infinate loop.
![]() |
Similar Threads
- Cubic equation (C++)
- converting truth table to boolean algebraic equation (Java)
- quadratic equation (C)
Other Threads in the Java Forum
- Previous Thread: Retrieve key by value in Hashtable
- Next Thread: Conver int Array into a String
Views: 2457 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addressbook android api append apple applet application arguments array arrays automation binary bluetooth character chat class classes client code component csv database detection draw eclipse error event exception file fractal ftp game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me japplet java javaarraylist javaprojects jmf jni jpanel julia linux list loop map method methods mobile netbeans newbie number object objects oracle oriented os panel print problem program programming project projects recursion replaydirector reporting researchinmotion return robot scanner score screen se server set size sms socket sort sql stream string swing test threads time transfer tree ubuntu windows






