Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  kingkross
Language: C/C++
Code:
#include <stdio.h>
#include <math.h>
const int n=2;
const int a=0,b=1;
const double h=0.01;
typedef double vector[n];
void dy();
void RK();

int i;
double x;
vector y,f;

void main()
{
  for(i=0;i<n;i++) {
     pointf("/nПочаткове згач Y[%d]-",i);
scanf("%if",&y[i]);
}
x=a;
do {
RK();
printf("\nx=%if \ty1=%if \ty2=%if",x,y[0],y[1]);
} while(x<b);

} //end main

void dy() //right
{ f[0]=y[1];
  f[1]=-y[0];
}
void RK()
{ vector k1,k2,k3,k4,z;
dy();
for(i=0;i<n;i++) {
   k1[i]=f[i];
z[i]=y[i];
y[i]=z[i]+0.5*h*k1[i];
}
x+=0.5*h;
dy();
for(i=0;i<n;i++) {
k2[i]=f[i];
y[i]=z[i]+0.5*h*k2[i];
}
dy();
for(i=0;i<n;i++) {
k3[i]=f[i];
y[i]=z[i]+h*k3[i];
}
x+=0.5*h;
dy();
for(i=0;i<n;i++) {
k4[i]=f[i];
y[i]=z[i]+h*(k1[i]+k4[i]+2*(k2[i]+k3[i]))/6;
}
}
          
Comments: