Malthusian Equation Help

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2004
Posts: 6
Reputation: Eclipse is an unknown quantity at this point 
Solved Threads: 0
Eclipse's Avatar
Eclipse Eclipse is offline Offline
Newbie Poster

Malthusian Equation Help

 
0
  #1
Nov 17th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Malthusian Equation Help

 
0
  #2
Nov 17th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 1,749
Reputation: nanosani is an unknown quantity at this point 
Solved Threads: 55
Team Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Malthusian Equation Help

 
0
  #3
Nov 17th, 2004
  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 ??
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 84
Reputation: jerbo is an unknown quantity at this point 
Solved Threads: 1
jerbo jerbo is offline Offline
Junior Poster in Training

Re: Malthusian Equation Help

 
0
  #4
Nov 17th, 2004
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':
  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2457 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC