943,935 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2776
  • Java RSS
Nov 17th, 2004
0

Malthusian Equation Help

Expand Post »
Quote ...
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.
Hey...okay, I really don't need much coding help for this, but I need some JAVA logic help. Once I understand the logic, I think I'll be able to get it. So basically, I need to create two methods I suppose, but I don't get the basis of this equation at all!!! This seems more like a math problem than a programming problem.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Eclipse is offline Offline
6 posts
since Oct 2004
Nov 17th, 2004
0

Re: Malthusian Equation Help

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 17th, 2004
0

Re: Malthusian Equation Help

Java Syntax (Toggle Plain Text)
  1.  
  2. Method( double R, double P){
  3.  
  4. P = R*P*(1-P);
  5.  
  6. return P;
  7. }
Is this what you want to do ??
Team Colleague
Reputation Points: 45
Solved Threads: 56
Unauthenticated Liar
nanosani is offline Offline
1,767 posts
since Jul 2004
Nov 17th, 2004
0

Re: Malthusian Equation Help

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':
Java Syntax (Toggle Plain Text)
  1. public int Malthusian {
  2. double saveP;
  3. double newP;
  4. boolean bflag = true;
  5. int returnVal = 0; // Initial value
  6.  
  7. // Assuming nano's method above returns a double:
  8. saveP = Method(5,1);
  9. while(bflag) {
  10. newP = Method(5,saveP);
  11. if (newP == saveP) {
  12. // Stable (do what you need to return this.)
  13. returnVal = 1; // Arbitrary value to denote Stable
  14. bflag = false;
  15. }
  16. if (P == 0) {
  17. // Extinct (do what you need to return this.)
  18. returnVal = 2; // Arbitrary value to denote Extinct
  19. bflag = false;
  20. }
  21. return returnVal; // Return the value
  22. }
  23. }

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.
Reputation Points: 11
Solved Threads: 1
Junior Poster in Training
jerbo is offline Offline
84 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Retrieve key by value in Hashtable
Next Thread in Java Forum Timeline: Conver int Array into a String





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC