Created
November 1, 2013 04:17
-
-
Save Corwinpro/7260896 to your computer and use it in GitHub Desktop.
Victim-predator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_DEPRECATE | |
#include "stdio.h" | |
#include "math.h" | |
#include "conio.h" | |
#include <iostream> | |
int a = 10; | |
int b = 2; | |
int c = 2; | |
int d = 10; | |
double U(double t,double x,double y) | |
{ | |
return a*x - b*x*y; | |
} | |
double V(double t,double x,double y) | |
{ | |
return c*x*y - d*y; | |
} | |
void solve() | |
{ | |
double t = 0; | |
double step = 0.001; | |
double x = 4.99; | |
double y = 5.01; | |
double q0, q1, q2, q3; | |
double k0, k1, k2, k3; | |
FILE * file; | |
file = fopen("file.txt", "w"); | |
while (t < 10.0) | |
{ | |
fprintf(file, "%.8e %.8e %.8e\n", t, x , y); | |
q0 = U(t, x, y); | |
k0 = V(t, x, y); | |
q1 = U(t+step/2.0,x+k0*step/2.0, y+q0*step/2.0); | |
k1 = V(t+step/2.0,x+k0*step/2.0, y+q0*step/2.0); | |
q2 = U(t+step/2.0,x+k1*step/2.0, y+q1*step/2.0); | |
k2 = V(t+step/2.0,x+k1*step/2.0, y+q1*step/2.0); | |
q3 = U(t+step,x+k2*step, y+q2*step); | |
k3 = V(t+step,x+k2*step, y+q2*step); | |
x = x + step*(k0+2.0*k1+2.0*k2+k3)/6.0; | |
y = y + step*(q0+2.0*q1+2.0*q2+k3)/6.0; | |
t = t + step; | |
} | |
fclose(file); | |
} | |
void main() | |
{ | |
solve(); | |
getchar(); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment