/* * reidai2.c -- 簡単な動画 (紙芝居?) * How to compile: ccx reidai2.c */ #include #include main() { /* 変数の宣言 */ int i, N, j, Jmax; double Pi, a, b, margin; double Time, h, dt, t, x, f(); /* Pi=円周率, a=区間の左端, b=区間の右端, margin=余白 */ Pi = M_PI; a = 0.0; b = 2.0 * Pi; margin = (b - a) / 20; /* x軸の区間の分割数、追跡時間の入力 */ printf("x軸上の区間の分割数="); scanf("%d", &N); printf("追跡時間="); scanf("%lf", &Time); /* 区間の刻み幅 */ h = (b - a) / N; /* グラフィックスの初期化 */ openpl(); fspace2(a - margin, -2.0, b + margin, 2.0); /* 時間間隔を決め、ループの回数を計算する */ dt = 1.0 / 16.0; Jmax = Time / dt + 0.5; /* ******* メイン・ループ ******* */ for (j = 0; j <= Jmax; j++) { t = j * dt; erase(); fmove(a, f(a, t)); for (i = 1; i <= N; i++) { x = a + i * h; fcont(x, f(x, t)); } xflush(); } /* ***** メイン・ループ終り ***** */ /* グラフィックスの後始末 */ closepl(); } /* * 両端を固定された弦のある3つの固有振動の和 * 時刻 t=0 では、例題1 に現われる関数に一致する */ double f(x, t) double x, t; { return sin(x) * cos(t) + sin(3 * x) * cos(3 * t) + sin(5 * x) * cos(5 * t); }