The predator-prey equations are:

dx/dt = ax − txy and

dy/dt = −cy + wxy

where, x and y are the populations of the prey and predator, respectively, at time t . a is the growth rate of the prey and c is the the death rate of the predator.And t and g are measures of the effect of the interaction between the two species.

Consider the initial conditions x0 = 1.0 and y0 = 0.5 , a=0.5, t=0.05, c=1.0, g=0.9.

1)Solve it by using improved Euler method.

2)plot x(t) & y(t) vs t.

That was my assignment . And I have come this far-

#include <iostream> #include<cmath> using namespace std; FILE * ppstream; int main() { int i=0, N=1000; double x=0.0, y=0.0, xp=0.0, t=0.0, h=0.001; double a=0.5, t=0.05, c=1.0, w=0.9, xprev=0.0, yprev=0.0; ppstream = fopen("predatorprey.data","w"); for(i=0; i<=N; i++) { xprev =0.0; xprev = a * x - t * x * y; xprev += a * (x + h *(a * x - t * x* y) ); xprev += - t*(x+h*(a*x - t *x* y))*(y + h *(-c*y + w *x* y) ); x = x + 0.5 * (xprev)* h; y = y + 0.5 * ( -c * y + w * x * y )* h; } fprintf(ppstream,"%8.4lf %10.8lf %10.8lf \n",t,x,y); fclose(ppstream); return 0; }

but still there are some bug in the code, it didnt prints the right values to obtain a graph. I have no hint what is the wrong in my code. Please help me to debug it...

And This is the algo... of improved Euler Method