Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python
#10
Thanks, that was very helpful Wink
unfortunately we can't import things since we haven't really 'learned' how to use it, on the test we can only use things that we've been taught.

I have another problem now, it's about lotka-volterra's equations.
if x is rabbits and y are wolves and the eco system variables are
a=3e-2
b=4e-5
c=5e-2
d=6e-6
I have to follow the equation for how it decreases everyday until rabbits are extinct:
x decrease = x(a-by)
y decrease = -y(c-dx)

if there's 300 rabbits and 400 wolves then how many days does it take for it to be rabbits<1
I have:
Code:
a=3e-2
b=4e-5
c=5e-2
d=6e-6
con=300.0
lob=400.0
t=0
while con > 1:
    p=con*(a-(b*lob))
    q=-lob*(c-(d*con))
    con=con-p
    lob=lob-q
    t=t+1
    print 'con=',con
    print 't=',t
print 'Los conejos se extinguiran en '+str(t)+' dias'

and the correct code is:

Code:
a = 3e-2
b = 4e-5
c = 5e-2
d = 6e-6

x = 300.0
y = 400.0

dias = 0

while y>1 :
    xi = x
    x = x + x*(a - b*y)
    y = y - y*(c - d*xi)
    dias += 1

print 'Los conejos se extinguen en', dias
I just can't see what's wrong with mine.

Edit: I found out what was wrong, apparently the condition for some reason is that wolves<1 which in my head makes no sense since it's rabbits that I'm waiting to be extinct.... my code is fine except that I thought the condition instead of just copying what was there
Reply


Messages In This Thread
Python - by Manu - 2011-03-30, 03:19 PM
Python - by Fiel - 2011-03-30, 03:40 PM
Python - by Manu - 2011-03-30, 03:54 PM
Python - by Fiel - 2011-03-30, 04:04 PM
Python - by Manu - 2011-03-30, 07:03 PM
Python - by Fiel - 2011-03-30, 07:16 PM
Python - by Manu - 2011-03-30, 08:11 PM
Python - by Manu - 2011-03-31, 08:16 PM
Python - by Fiel - 2011-04-01, 03:12 AM
Python - by Manu - 2011-04-01, 08:27 PM
Python - by Fiel - 2011-04-01, 08:38 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)