function Predator_prey2alpha = 0.4;beta = 0.8;gamma = 0.7;delta = 1;epsilon = 0.5;eta = 0.9;lambda = 0.6;xold = 0.8;yold = 0.8;zold = 0.8;tMin = 0;tMax = 50;tChange = 0.001;figure;subplot(1,2,1);hold on;grid on;axis( [-0.2 2 0.1 2 0.1 2]);title ('Populations of foxes rabbits and chickens');xlabel ('Population of chickens');ylabel ('Population of rabbits');zlabel ('Population of foxes');xs = []; ys = []; zs = []; ts = [];subplot(1,2,2);hold on;axis([tMin tMax 0.5 2.2]);title('Population');xlabel('Time');ylabel('Population size');for t = tMin:tChange:tMax; xs = [xs, xold]; ys = [ys, yold]; zs = [zs, zold]; ts = [ts, t]; yNew = yold+tChange*(delta-epsilon*zold); xNew = xold+tChange*(eta-lambda*zold); zNew = zold+tChange*(beta*yold-alpha*zold+gamma*xold); xold = xNew; yold = yNew; zold = zNew; if mod(t,1)==0 subplot(1,2,1); plot(xs, ys, zs,'e.'); subplot(1,2,2); plot(ts,xs,'f.',ts,ys,'g.',ts,zs,'h.'); legend('Chickens','Rabbits','Foxes'); pause(0.01); end end
I have a predator-prey problem, where I have 1 predator and 2 preys. Could you please help me, where might be problem?
Best Answer