コード例 #1
0
void test_integration(void) {
  function_t *f = function_create("2**x - log(x)");
  ASSERT_EQ(integrate_simpson(f, 0.5, 2.3), 4.60212);
  function_destroy(f);

  f = function_create("1/x - sin(x)**3");
  ASSERT_EQ(integrate_simpson(f, 2.45, 8.145), 1.54018);
  function_destroy(f);
}
コード例 #2
0
ファイル: 1.c プロジェクト: martin-ueding/physik441-Programme
void problem1() {
	int k = 0;

	double integral = 0;
	double step = 0;
	double step_old;

	FILE *fp = fopen("out-1a.txt", "w");
	fprintf(fp, "#%4s %5s %15s %15s\n", "k", "n", "step", "integral");
	do {
		int n = 2;
		do {
			step_old = step;
			step = integrate_simpson(f1, 100 * k, 100 * (k+1), n);
			n *= 2;
			fprintf(fp, "%5i %5i %15g %15g\n", k, n, step, integral);
		} while (fabs(step - step_old) > 1e-10);
		integral += step;
		k++;
	} while (fabs(step) >= 1e-5);
	fclose(fp);
}