1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include "stdafx.h"
#include<iostream>
using namespace std;
double f1(int n,double *yy1,double *yy2,double *yy3)
{
double f1 = -0.01*yy1[n] + 10*yy2[n]*yy3[n];
return f1;
}
double f2(int n,double *yy1,double *yy2,double *yy3)
{
double f2 = 0.01*yy1[n] - 10*yy2[n]*yy3[n]-10000*yy2[n]*yy2[n];
return f2;
}
double f3(int n,double *yy1,double *yy2,double *yy3)
{
double f3 = 10000*yy2[n]*yy2[n];
return f3;
}
int main()
{
int i=0;
double *y1 = new double[i];
double *y2 = new double[i];
double *y3 = new double[i];
double k11=0,k21=0,k31=0,k41=0,k12=0,k22=0,k32=0,k42=0,k13=0,k23=0,k33=0,k43=0,h=0.0001;
//double y1[0]=1,y2[0]=0,y3[0]=0;
//int nSize = 12;
// note: nSize does not need to be constant!
//pnArray[4] = 7;
//delete[] pnArray;
for (i=0; i<3; i++)
{
y1[0]=1,y2[0]=0,y3[0]=0;
k11 = -0.01*y1[i] + 10*y2[i]*y3[i];
k21 = -0.01*(y1[i] + .5*h*k11) + 10*(y2[i] + .5*h*k11)*(y3[i]+.5*h*k11);
k31 = -0.01*(y1[i] + .5*h*k21) + 10*(y2[i] + .5*h*k21)*(y3[i]+.5*h*k21);
k41 = -0.01*(y1[i] + h*k31) + 10*(y2[i] + h*k31)*(y3[i]+h*k31);
y1[i+1] = y1[i] + (h*(k11+2*k21+2*k31+k41))/6;
//cout << "*" <<endl;
k12 = 0.01*y1[i] - 10*y2[i]*y3[i]-10000*y2[i]*y2[i];
k22 = 0.01*(y1[i] + .5*h*k12) - 10*(y2[i] + .5*h*k12)*(y3[i]+.5*h*k12)-10000*(y2[i]+.5*h*k12)*(y2[i]+.5*h*k12);
k32 = 0.01*(y1[i] + .5*h*k22) - 10*(y2[i] + .5*h*k22)*(y3[i]+.5*h*k22)-10000*(y2[i]+.5*h*k22)*(y2[i]+.5*h*k22);
k42 = 0.01*(y1[i] + h*k32) - 10*(y2[i] + h*k32)*(y3[i]+h*k32)-10000*(y2[i]+h*k32)*(y2[i]+h*k32);
y2[i+1] = y2[i] + (h*(k12+2*k22+2*k32+k42))/6;
//cout << "**" <<endl;
k13 = 10000*y2[i]*y2[i];
k23 = 10000*(y2[i]+.5*h*k13)*(y2[i]+.5*h*k13);
k33 = 10000*(y2[i]+.5*h*k23)*(y2[i]+.5*h*k23);
k43 = 10000*(y2[i]+h*k33)*(y2[i]+h*k33);
y3[i+1] = y3[i] + (h*(k13+2*k23+2*k33+k43))/6;
//cout << "***" <<endl;
//fprintf (rkFiley1, " %lf\n",y1[i]1);
//fprintf (rkFiley2, " %lf\n",y2[i]1);
//fprintf (rkFiley3, " %lf\n",y3[i]1);
//y1[i] = y1[i]1;
//y2[i] = y2[i]1;
//y3[i] = y3[i]1;
}
double t= 0.0003;
//int i=3;
while (t<=100)
{
t = t + h ;
y1[i+1] = y1[i] + (h*(55*f1(i,&y1[i],&y2[i],&y3[i]) - 59*f1(i-1,&y1[i-1],&y2[i-1],&y3[i-1]) + 37*f1(i-2,&y1[i-2],&y2[i-2],&y3[i-2]) - 9*f1(i-3,&y1[i-3],&y2[i-3],&y3[i-3]))/24);
y1[i+1] = y1[i] + (h*(8*f1(i+1,&y1[i+1],&y2[i+1],&y3[i+1]) + 19*f1(i,&y1[i],&y2[i],&y3[i]) -+ 5*f1(i-1,&y1[i-1],&y2[i-1],&y3[i-1]) + f1(i-2,&y1[i-2],&y2[i-2],&y3[i-2]))/24);
y2[i+1] = y2[i] + (h*(55*f2(i,&y1[i],&y2[i],&y3[i]) - 59*f2(i-1,&y1[i-1],&y2[i-1],&y3[i-1]) + 37*f2(i-2,&y1[i-2],&y2[i-2],&y3[i-2]) - 9*f2(i-3,&y1[i-3],&y2[i-3],&y3[i-3]))/24);
y2[i+1] = y2[i] + (h*(8*f2(i+1,&y1[i+1],&y2[i+1],&y3[i+1]) + 19*f2(i,&y1[i],&y2[i],&y3[i]) -+ 5*f2(i-1,&y1[i-1],&y2[i-1],&y3[i-1]) + f2(i-2,&y1[i-2],&y2[i-2],&y3[i-2]))/24);
y3[i+1] = y3[i] + (h*(55*f3(i,&y1[i],&y2[i],&y3[i]) - 59*f3(i-1,&y1[i-1],&y2[i-1],&y3[i-1]) + 37*f3(i-2,&y1[i-2],&y2[i-2],&y3[i-2]) - 9*f3(i-3,&y1[i-3],&y2[i-3],&y3[i-3]))/24);
y3[i+1] = y3[i] + (h*(8*f3(i+1,&y1[i+1],&y2[i+1],&y3[i+1]) + 19*f3(i,&y1[i],&y2[i],&y3[i]) -+ 5*f3(i-1,&y1[i-1],&y2[i-1],&y3[i-1]) + f3(i-2,&y1[i-2],&y2[i-2],&y3[i-2]))/24);
i++;
}
cout << y1 << endl;
cout << y2 << endl;
cout << y3 << endl;
return 0;
}
|