Вопрос

I am trying to apply Rk4 via butcher tablaeu for pendulum, at first i was getting logical results but now i keep getting no sense results in the compiler after closing editor by mistake. I tried #define functions but still nothing , dunno what's going on - either my code is not well written or there is some stupid mistake i can't see, any help would be appreciated.

#include <stdio.h>
#include <math.h>
#define N 300.0
#define L 9.81
#define g 9.81
#define pi 3.141592

#define a21 0.5
#define a31 0
#define a32 0.5
#define a41 0
#define a42 0
#define a43 1.0
#define c2 0.5
#define c3 0.5
#define c4 1.0
#define w1 1/6
#define w2 1/3
#define w3 1/3
#define w4 1/6



double g1(double y1,double y2,double t0);
double g2(double y1,double y2,double t0);

double g1(double y1,double y2,double t0)
{
return (y2);
}


double g2(double y1,double y2,double t0)
{
return (-(g/L)*(y1));
}


int main()
{


double h,t0=0,k11,k21,k12,k22,k13,k23,k14,k24;
double y1,y2;
double y[2][N];


h  = 0.1;

y[0][0] = 0;
y[1][0] = 0.1745;


for (int i = 1;  i <= N; i++)
 {
 t0 = h*(i);
 y1 = y[0][i-1];
 y2 = y[1][i-1];
 k11 = h*g1(y1,y2,t0);
 k21 = h*g2(y1,y2,t0);
 k12 = h*g1((y1+k11*a21),(y2+k21*a21),(t0+h*c2));
 k22 = h*g2((y1+k11*a21),(y2+k21*a21),(t0+h*c2));
 k13 = h*g1((y1+k12*a32+k11*a31),(y2+k22*a32+k21*a31),(t0+h*c3));
 k23 = h*g2((y1+k12*a32+k11*a31),(y2+k22*a32+k21*a31),(t0+h*c3));
 k14 = h*g1((y1+k13*a43+k12*a42+k11*a41),(y2+k23*a43+k22*a42+k21*a41),(t0+h*c4));
 k24 = h*g2((y1+k13*a43+k12*a42+k11*a41),(y2+k23*a43+k22*a42+k21*a41),(t0+h*c4));
 y[0][i] = y[0][i-1]+ w1*k11 + w2*k12 + w3*k13 + w4*k14;
 y[1][i] = y[1][i-1]+ w1*k21 + w2*k22 + w3*k23 + w4*k24;


 printf(" theta[%d]=%lf || omega[%d]=%lf", i,y[0][i],i,y[1][i]);
 printf("\n");

 }
}

Нет правильного решения

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top