C语言-预估校正法求常微分方程
#include<stdio.h> #include<math.h> #define n 14 int main(){ double a = 0.0, b = 1.4,h,m=0.0; //int n = 14; double x[n + 1] = { 0.0 }, y[n + 1] = { 0 }; h = (b - a) / n; x[0] = a; y[0] = m; for (int i = 1; i <= n; i++) { y[i] = y[i - 1] + h*(1 + y[i - 1] * y[i - 1]); x[i] = a + i*h; y[i] = y[i - 1] + h*0.5*((1 + y[i - 1] * y[i - 1]) + (1+y[i]*y[i])); printf("x[%d]=%e , y[%d]=%e\n",i, x[i], i, y[i]); } return 0; }